From b21eb999567115594f7e1f686c80fdea9eb9a16d Mon Sep 17 00:00:00 2001 From: Metaphilibert Date: Fri, 14 Jun 2019 03:12:01 +0200 Subject: [PATCH 001/659] Cosmetics for legacy view --- src/miner.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9976909fa..31345cdd7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1746,7 +1746,7 @@ void static BitcoinMiner() if ( (Mining_height >= 235300 && Mining_height < 236000) || (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 || Mining_height > 1000000 ) { int32_t dispflag = 0; - if ( notaryid <= 3 || notaryid == 32 || (notaryid >= 43 && notaryid <= 45) &¬aryid == 51 || notaryid == 52 || notaryid == 56 || notaryid == 57 ) + if ( notaryid <= 3 || notaryid == 32 || (notaryid >= 43 && notaryid <= 45) || notaryid == 51 || notaryid == 52 || notaryid == 56 || notaryid == 57 ) dispflag = 1; komodo_eligiblenotary(pubkeys,mids,blocktimes,&nonzpkeys,pindexPrev->GetHeight()); if ( nonzpkeys > 0 ) @@ -1769,8 +1769,12 @@ void static BitcoinMiner() if ( dispflag != 0 ) { if ( mids[j] >= 0 ) - fprintf(stderr,"%d ",mids[j]); - else fprintf(stderr,"GPU "); + { + if ( mids[j] == notaryid ) + fprintf(stderr,"--<%d>-- ",mids[j]); + else + fprintf(stderr,"%d ",mids[j]); + } else fprintf(stderr,"GPU "); } if ( mids[j] == -1 ) gpucount++; From ed9ff35e7ad7deaed617b56fd107cc75c1137c03 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Jun 2019 22:12:56 -1100 Subject: [PATCH 002/659] Misc syntax tweaks --- src/cc/crypto777/OS_portable.h | 12 ++++++------ src/cc/dapps/cJSON.c | 5 ++++- src/cc/dapps/zmigrate.c | 31 +++++++++++++++++-------------- src/cc/includes/curve25519.h | 2 +- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/cc/crypto777/OS_portable.h b/src/cc/crypto777/OS_portable.h index aeb45bc32..e0b185cbc 100755 --- a/src/cc/crypto777/OS_portable.h +++ b/src/cc/crypto777/OS_portable.h @@ -206,12 +206,12 @@ void OS_nonportable_randombytes(uint8_t *x,long xlen); int32_t OS_nonportable_init(); #endif -void OS_portable_init(); -void OS_init(); +void OS_portable_init(void); +void OS_init(void); int32_t sortds(double *buf,uint32_t num,int32_t size); int32_t revsortds(double *buf,uint32_t num,int32_t size); -double OS_portable_milliseconds(); +double OS_portable_milliseconds(void); void OS_portable_randombytes(uint8_t *x,long xlen); int32_t OS_portable_truncate(char *fname,long filesize); char *OS_portable_path(char *str); @@ -256,7 +256,7 @@ int32_t OS_removefile(char *fname,int32_t scrubflag); void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite); int32_t OS_releasemap(void *ptr,unsigned long filesize); -double OS_milliseconds(); +double OS_milliseconds(void); void OS_randombytes(uint8_t *x,long xlen); //int32_t OS_syncmap(struct OS_mappedptr *mp,long len); @@ -313,7 +313,7 @@ void sort64s(uint64_t *buf,uint32_t num,int32_t size); void revsort64s(uint64_t *buf,uint32_t num,int32_t size); int decode_base32(uint8_t *token,uint8_t *tokenstr,int32_t len); int init_base32(char *tokenstr,uint8_t *token,int32_t len); -char *OS_mvstr(); +char *OS_mvstr(void); long _stripwhite(char *buf,int accept); int32_t is_DST(int32_t datenum); @@ -381,7 +381,7 @@ double dxblend(double *destp,double val,double decay); uint64_t calc_ipbits(char *ip_port); void expand_ipbits(char *ipaddr,uint64_t ipbits); void escape_code(char *escaped,char *str); -void SaM_PrepareIndices(); +void SaM_PrepareIndices(void); // iguana_serdes.c #ifndef IGUANA_LOG2PACKETSIZE diff --git a/src/cc/dapps/cJSON.c b/src/cc/dapps/cJSON.c index 62f46444c..e1d7801a1 100644 --- a/src/cc/dapps/cJSON.c +++ b/src/cc/dapps/cJSON.c @@ -40,7 +40,10 @@ long stripquotes(char *str) return(0); len = strlen(str); if ( str[0] == '"' && str[len-1] == '"' ) - str[len-1] = 0, offset = 1; + { + str[len-1] = 0; + offset = 1; + } else offset = 0; return(offset); } diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index ea8085822..f7d9e3feb 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -1041,6 +1041,7 @@ int32_t itemvalid(char *refcoin,int64_t *refundedp,int64_t *waitingp,struct clai *refundedp = *waitingp = 0; if ( item->refundvalue < 0 ) return(-1); + // change "kmd" -> %s, tolowerstr(refcoin) sprintf(url,"https://kmd.explorer.dexstats.info/insight-api-komodo/addr/%s",item->destaddr); if ( (retstr= send_curl(url,"/tmp/itemvalid")) != 0 ) { @@ -1061,7 +1062,7 @@ int32_t itemvalid(char *refcoin,int64_t *refundedp,int64_t *waitingp,struct clai } free_json(curljson); } - //printf("%s\n",retstr); + printf("%s\n",retstr); free(retstr); } if ( item->approved != 0 ) @@ -1086,18 +1087,19 @@ void scan_claims(int32_t issueflag,char *refcoin,int32_t batchid) else if ( batchid == 2 ) { batchmin = 1;//777 * SATOSHIDEN; - batchmax = 77777 * SATOSHIDEN; + batchmax = 5000 * SATOSHIDEN; } else if ( batchid == 3 ) { - batchmin = 77777 * SATOSHIDEN; - batchmax = 1000000 * SATOSHIDEN; + batchmin = 1;//117777 * SATOSHIDEN; + batchmax = 10000000 * SATOSHIDEN; } for (i=0; irefundvalue < batchmin || item->refundvalue >= batchmax ) continue; + printf("check.%d %s %.8f vs refund %.8f -> %s\n",batchid,item->oldaddr,dstr(item->total),dstr(item->refundvalue),item->destaddr); if ( itemvalid(refcoin,&refunded,&waiting,item) < 0 ) { if ( refunded != 0 ) @@ -1170,7 +1172,7 @@ int32_t update_claimvalue(int32_t *disputedp,char *addr,int64_t amount,bits256 t item = &CLAIMS[i]; item->refundvalue = amount; if ( bits256_nonz(item->txid) != 0 ) - printf("disputed.%d %s claimed %.8f vs %.8f\n",item->disputed,addr,dstr(item->total),dstr(amount)); + printf("disputed.%d (%s) %s claimed %.8f vs %.8f\n",item->disputed,item->username,addr,dstr(item->total),dstr(amount)); item->txid = txid; if ( item->disputed != 0 ) *disputedp = 1; @@ -1183,6 +1185,7 @@ int32_t update_claimvalue(int32_t *disputedp,char *addr,int64_t amount,bits256 t int64_t update_claimstats(char *username,char *oldaddr,char *destaddr,int64_t amount) { int32_t i; struct claimitem *item; + printf("claim user.(%s) (%s) -> (%s) %.8f\n",username,oldaddr,destaddr,dstr(amount)); for (i=0; idestaddr) != 0 )//|| strcmp(username,item->username) != 0 ) { item->disputed++; - printf("disputed.%d claim.%-4d: (%36s -> %36s %s) vs. (%36s -> %36s %s) \n",item->disputed,i,oldaddr,destaddr,username,item->oldaddr,item->destaddr,item->username); + printf("disputed.%d claim.%-4d: (%36s -> [%36s] %s) vs. (%36s -> [%36s] %s) \n",item->disputed,i,oldaddr,destaddr,username,item->oldaddr,item->destaddr,item->username); } item->numutxos++; item->total += amount; @@ -1258,14 +1261,14 @@ int64_t sum_of_vins(char *refcoin,int32_t *totalvinsp,int32_t *uniqaddrsp,bits25 return(total); } -void reconcile_claims(char *fname) +void reconcile_claims(char *refcoin,char *fname) { FILE *fp; double amount; int32_t i,n,numlines = 0; char buf[1024],fields[16][256],*str; int64_t total = 0; if ( (fp= fopen(fname,"rb")) != 0 ) { while ( fgets(buf,sizeof(buf),fp) > 0 ) { - //printf("%d.(%s)\n",numlines,buf); + printf("%d.(%s)\n",numlines,buf); str = buf; n = i = 0; memset(fields,0,sizeof(fields)); @@ -1277,7 +1280,7 @@ void reconcile_claims(char *fname) i = 0; if ( n > 1 ) { - //printf("(%16s) ",fields[n]); + printf("(%16s) ",fields[n]); } n++; if ( *str == '\n' || *str == '\r' ) @@ -1287,8 +1290,8 @@ void reconcile_claims(char *fname) str++; else fields[n][i++] = *str++; } - //printf("%s\n",fields[0]); - total += update_claimstats(fields[1],fields[3],fields[6],atof(fields[4])*SATOSHIDEN + 0.0000000049); + printf("%s\n",fields[1]); + total += update_claimstats(fields[1],fields[3],fields[5 + (strcmp("KMD",refcoin)==0)],atof(fields[4])*SATOSHIDEN + 0.0000000049); numlines++; } fclose(fp); @@ -1326,7 +1329,7 @@ int32_t main(int32_t argc,char **argv) if ( 1 )//strcmp(coinstr,"KMD") == 0 ) { sprintf(buf,"%s-Claims.csv",coinstr); - reconcile_claims(buf); + reconcile_claims(coinstr,buf); for (i=0; i> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); From 896b6fee53fe52eac6bc5cb9d65f1886d44dbed9 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Sun, 30 Jun 2019 15:38:27 +0200 Subject: [PATCH 003/659] fix createrawtransaction curl example --- src/rpc/rawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 578c2f9ad..7d490dff2 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -757,7 +757,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) "\nExamples\n" + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01}\"") - + HelpExampleRpc("createrawtransaction", "\"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01}\"") + + HelpExampleRpc("createrawtransaction", "[{\"txid\":\"myid\",\"vout\":0}], {\"address\":0.01}") ); LOCK(cs_main); From 5e6737fc389db5aec0ebedb99230478b4a49dc09 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Mon, 1 Jul 2019 19:03:52 +0200 Subject: [PATCH 004/659] add additional param to importprivkey for other WIF formats --- src/key_io.cpp | 16 ++++++++++++++++ src/key_io.h | 1 + src/rpc/client.cpp | 1 + src/wallet/rpcdump.cpp | 12 ++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/key_io.cpp b/src/key_io.cpp index 014159d65..dd4176fee 100644 --- a/src/key_io.cpp +++ b/src/key_io.cpp @@ -207,6 +207,22 @@ CKey DecodeSecret(const std::string& str) return key; } +CKey DecodeCustomSecret(const std::string& str, uint8_t secret_key) +{ + CKey key; + std::vector data; + if (DecodeBase58Check(str, data)) { + const std::vector& privkey_prefix = std::vector(1, secret_key); + if ((data.size() == 32 + privkey_prefix.size() || (data.size() == 33 + privkey_prefix.size() && data.back() == 1)) && + std::equal(privkey_prefix.begin(), privkey_prefix.end(), data.begin())) { + bool compressed = data.size() == 33 + privkey_prefix.size(); + key.Set(data.begin() + privkey_prefix.size(), data.begin() + privkey_prefix.size() + 32, compressed); + } + } + memory_cleanse(data.data(), data.size()); + return key; +} + std::string EncodeSecret(const CKey& key) { assert(key.IsValid()); diff --git a/src/key_io.h b/src/key_io.h index 72823d57e..013469ab6 100644 --- a/src/key_io.h +++ b/src/key_io.h @@ -17,6 +17,7 @@ #include CKey DecodeSecret(const std::string& str); +CKey DecodeCustomSecret(const std::string& str, uint8_t secret_key); std::string EncodeSecret(const CKey& key); std::string EncodeCustomSecret(const CKey& key,uint8_t secret_key); diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 3f0f9dea8..665887b3b 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -109,6 +109,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "lockunspent", 1 }, { "importprivkey", 2 }, { "importprivkey", 3 }, + { "importprivkey", 4 }, { "importaddress", 2 }, { "verifychain", 0 }, { "verifychain", 1 }, diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 05552b50b..10048c79e 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -94,7 +94,7 @@ UniValue importprivkey(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() < 1 || params.size() > 4) + if (fHelp || params.size() < 1 || params.size() > 5) throw runtime_error( "importprivkey \"komodoprivkey\" ( \"label\" rescan height)\n" "\nAdds a private key (as returned by dumpprivkey) to your wallet.\n" @@ -126,6 +126,7 @@ UniValue importprivkey(const UniValue& params, bool fHelp) string strSecret = params[0].get_str(); string strLabel = ""; int32_t height = 0; + uint8_t secret_key = 0; if (params.size() > 1) strLabel = params[1].get_str(); @@ -136,10 +137,17 @@ UniValue importprivkey(const UniValue& params, bool fHelp) if ( fRescan && params.size() == 4 ) height = params[3].get_int(); + CKey key = DecodeSecret(strSecret); + + if (params.size() > 4) + { + secret_key = params[4].get_int(); + CKey key = DecodeCustomSecret(strSecret, secret_key); + } + if ( height < 0 || height > chainActive.Height() ) throw JSONRPCError(RPC_WALLET_ERROR, "Rescan height is out of range."); - CKey key = DecodeSecret(strSecret); if (!key.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding"); CPubKey pubkey = key.GetPubKey(); From 89874a01ce6a8fab42538275f8965b4e6f032830 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Mon, 1 Jul 2019 21:06:36 +0200 Subject: [PATCH 005/659] fix CKey declaration --- src/wallet/rpcdump.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 10048c79e..3bd54aff5 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -127,6 +127,7 @@ UniValue importprivkey(const UniValue& params, bool fHelp) string strLabel = ""; int32_t height = 0; uint8_t secret_key = 0; + CKey key; if (params.size() > 1) strLabel = params[1].get_str(); @@ -137,12 +138,13 @@ UniValue importprivkey(const UniValue& params, bool fHelp) if ( fRescan && params.size() == 4 ) height = params[3].get_int(); - CKey key = DecodeSecret(strSecret); if (params.size() > 4) { - secret_key = params[4].get_int(); - CKey key = DecodeCustomSecret(strSecret, secret_key); + auto secret_key = AmountFromValue(params[4])/100000000; + key = DecodeCustomSecret(strSecret, secret_key); + } else { + key = DecodeSecret(strSecret); } if ( height < 0 || height > chainActive.Height() ) From 8a958a275e7efd4215e09a75793f3e8a3940a75b Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Mon, 1 Jul 2019 21:21:46 +0200 Subject: [PATCH 006/659] fix importprivkey help message --- src/wallet/rpcdump.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 3bd54aff5..b4a413f6d 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -96,13 +96,14 @@ UniValue importprivkey(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 5) throw runtime_error( - "importprivkey \"komodoprivkey\" ( \"label\" rescan height)\n" + "importprivkey \"komodoprivkey\" ( \"label\" rescan height secret_key)\n" "\nAdds a private key (as returned by dumpprivkey) to your wallet.\n" "\nArguments:\n" "1. \"komodoprivkey\" (string, required) The private key (see dumpprivkey)\n" "2. \"label\" (string, optional, default=\"\") An optional label\n" "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n" "4. height (integer, optional, default=0) start at block height?\n" + "5. secret_key (interger, optional, default=188) used to import WIFs of other coins\n" "\nNote: This call can take minutes to complete if rescan is true.\n" "\nExamples:\n" "\nDump a private key\n" @@ -115,6 +116,10 @@ UniValue importprivkey(const UniValue& params, bool fHelp) + HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false") + "\nImport with rescan from a block height\n" + HelpExampleCli("importprivkey", "\"mykey\" \"testing\" true 1000") + + "\nImport a BTC WIF with rescan\n" + + HelpExampleCli("importprivkey", "\"BTCWIF\" \"testing\" true 0 128") + + "\nImport a BTC WIF without rescan\n" + + HelpExampleCli("importprivkey", "\"BTCWIF\" \"testing\" false 0 128") + "\nAs a JSON-RPC call\n" + HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", true, 1000") ); From abc90c501b4ec4914bb72afaff4317a9c16bdbd1 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Mon, 1 Jul 2019 21:41:53 +0200 Subject: [PATCH 007/659] typo, sorry --- src/wallet/rpcdump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index b4a413f6d..563fc875c 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -103,7 +103,7 @@ UniValue importprivkey(const UniValue& params, bool fHelp) "2. \"label\" (string, optional, default=\"\") An optional label\n" "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n" "4. height (integer, optional, default=0) start at block height?\n" - "5. secret_key (interger, optional, default=188) used to import WIFs of other coins\n" + "5. secret_key (integer, optional, default=188) used to import WIFs of other coins\n" "\nNote: This call can take minutes to complete if rescan is true.\n" "\nExamples:\n" "\nDump a private key\n" From f4a001d2a2c63895ac1d02eec9c905234d27bf84 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Tue, 2 Jul 2019 08:26:22 +0300 Subject: [PATCH 008/659] ip --- src/assetchains.old | 52 ++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/assetchains.old b/src/assetchains.old index 4cf427c4d..1784bf2e1 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -4,37 +4,37 @@ delay=60 source pubkey.txt echo $pubkey -./komodod -pubkey=$pubkey -ac_name=REVS -ac_supply=1300000 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=SUPERNET -ac_supply=816061 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=DEX -ac_supply=999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=PANGEA -ac_supply=999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=JUMBLR -ac_supply=999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=BET -ac_supply=999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=COQUI -ac_supply=72000000 -ac_ccactivate=200000 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=WLC -ac_supply=210000000 -addnode=148.251.190.89 $1 & -./komodod -pubkey=$pubkey -ac_name=KV -ac_supply=1000000 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=CEAL -ac_supply=366666666 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=MESH -ac_supply=1000007 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=AXO -ac_supply=200000000 -ac_ccactivate=130000 -addnode=78.47.196.146 & -./komodod -pubkey=$pubkey -ac_name=ETOMIC -ac_supply=100000000 -addnode=78.47.196.146 & -./komodod -pubkey=$pubkey -ac_name=BTCH -ac_supply=20998641 -addnode=78.47.196.146 & -./komodod -pubkey=$pubkey -ac_name=BEER -ac_supply=100000000 -addnode=78.47.196.146 & -./komodod -pubkey=$pubkey -ac_name=PIZZA -ac_supply=100000000 -addnode=78.47.196.146 & -./komodod -pubkey=$pubkey -ac_name=NINJA -ac_supply=100000000 -addnode=78.47.196.146 & -./komodod -pubkey=$pubkey -ac_name=OOT -ac_supply=216000000 -ac_sapling=5000000 -addnode=174.138.107.226 & -./komodod -pubkey=$pubkey -ac_name=BNTN -ac_supply=500000000 -addnode=94.130.169.205 & -./komodod -pubkey=$pubkey -ac_name=CHAIN -ac_supply=999999 -addnode=78.47.146.222 & +./komodod -pubkey=$pubkey -ac_name=REVS -ac_supply=1300000 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=SUPERNET -ac_supply=816061 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=DEX -ac_supply=999999 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=PANGEA -ac_supply=999999 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=JUMBLR -ac_supply=999999 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=BET -ac_supply=999999 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=COQUI -ac_supply=72000000 -ac_ccactivate=200000 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=WLC -ac_supply=210000000 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=KV -ac_supply=1000000 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=CEAL -ac_supply=366666666 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=MESH -ac_supply=1000007 -addnode=95.213.238.98 $1 & +./komodod -pubkey=$pubkey -ac_name=AXO -ac_supply=200000000 -ac_ccactivate=130000 -addnode=95.213.238.98 & +./komodod -pubkey=$pubkey -ac_name=ETOMIC -ac_supply=100000000 -addnode=95.213.238.98 & +./komodod -pubkey=$pubkey -ac_name=BTCH -ac_supply=20998641 -addnode=95.213.238.98 & +./komodod -pubkey=$pubkey -ac_name=BEER -ac_supply=100000000 -addnode=95.213.238.98 & +./komodod -pubkey=$pubkey -ac_name=PIZZA -ac_supply=100000000 -addnode=95.213.238.98 & +./komodod -pubkey=$pubkey -ac_name=NINJA -ac_supply=100000000 -addnode=95.213.238.98 & +./komodod -pubkey=$pubkey -ac_name=OOT -ac_supply=216000000 -ac_sapling=5000000 -addnode=95.213.238.98 & +./komodod -pubkey=$pubkey -ac_name=BNTN -ac_supply=500000000 -addnode=95.213.238.98 & +./komodod -pubkey=$pubkey -ac_name=CHAIN -ac_supply=999999 -addnode=95.213.238.98 & ./komodod -pubkey=$pubkey -ac_name=PRLPAY -ac_supply=500000000 -addnode=13.250.226.125 & ./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 & ./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=10000000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -ac_ccactivate=205000 -addnode=46.101.124.153 & ./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -ac_sapling=5000000 -addnode=51.68.215.104 & -./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=95.213.238.98 & ~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & ./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & ./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & From 98747a7bdffe4a23f5ed6692c93986ea612257bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 00:36:06 -1100 Subject: [PATCH 009/659] txid --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9a80e5e24..1006a9ada 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -652,6 +652,7 @@ const char *banned_txids[] = //"01d8c839463bda2f2f6400ede4611357913684927a767422a8560ead1b22557c", //"6e4980a9e1bd669f4df04732dc6f11b7773b6de88d1abcf89a6b9007d72ef9ac", //"6cc1d0495170bc0e11fd3925297623562e529ea1336b66ea61f8a1159041aed2", + //"250875424cece9bcd98cb226b09da7671625633d6958589e3a462bad89ad87cc", // missed }; int32_t komodo_checkvout(int32_t vout,int32_t k,int32_t indallvouts) From 57394a34c01544522bf7a766ada64fbdbc440c8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 01:21:07 -1100 Subject: [PATCH 010/659] KOMODO_NSPV init bypass --- src/init.cpp | 11 ++++++++--- src/komodo_defs.h | 2 +- src/komodo_utils.h | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 107e3e476..d61426722 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -90,12 +90,10 @@ using namespace std; +#include "komodo_defs.h" extern void ThreadSendAlert(); extern bool komodo_dailysnapshot(int32_t height); extern int32_t KOMODO_LOADINGBLOCKS; -extern bool VERUS_MINTBLOCKS; -extern char ASSETCHAINS_SYMBOL[]; -extern int32_t KOMODO_SNAPSHOT_INTERVAL; ZCJoinSplit* pzcashParams = NULL; @@ -1478,6 +1476,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } #endif + if ( KOMODO_NSPV != 0 ) + { + std::vector vImportFiles; + threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles)); + StartNode(threadGroup, scheduler); + return !fRequestShutdown; + } // ********************************************************* Step 7: load block chain fReindex = GetBoolArg("-reindex", false); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 7be46f613..6106a6000 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -271,7 +271,7 @@ extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_FOUNDERS_REWARD; extern uint64_t ASSETCHAINS_TIMELOCKGTE; extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH,KOMODO_INITDONE; -extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE,ASSETCHAINS_STAKED; +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE,ASSETCHAINS_STAKED,KOMODO_NSPV; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_LASTERA,ASSETCHAINS_CBOPRET; extern bool VERUS_MINTBLOCKS; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1bf8dfbeb..134551b0d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1695,6 +1695,7 @@ void komodo_args(char *argv0) std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512] = {0}; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); IS_STAKED_NOTARY = GetArg("-stakednotary", -1); + KOMODO_NSPV = GetArg("-nSPV",0); memset(ccenables,0,sizeof(ccenables)); memset(disablebits,0,sizeof(disablebits)); if ( GetBoolArg("-gen", false) != 0 ) From 5e7fb0d473619419ba448b2c017829715677a432 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 01:33:27 -1100 Subject: [PATCH 011/659] Declare KOMODO_NSPV --- src/komodo_globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index d8e292431..c88b675a2 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -46,7 +46,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; uint256 KOMODO_EARLYTXID; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,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,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,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,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,KOMODO_NSPV; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; From 1e80fc44ecb3bae39e531b9b932432e34d5242d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 01:39:12 -1100 Subject: [PATCH 012/659] Check null LastTip() --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e01cba61f..67ba03d79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -352,7 +352,9 @@ namespace { int GetHeight() { - return chainActive.LastTip()->GetHeight(); + if ( chainActive.LastTip() != 0 ) + return chainActive.LastTip()->GetHeight(); + else return(-1); } void UpdatePreferredDownload(CNode* node, CNodeState* state) From ce86a489eb546a7438ec4185a2ea759db23922bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 01:39:54 -1100 Subject: [PATCH 013/659] - function call --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 67ba03d79..a772de50b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -352,8 +352,9 @@ namespace { int GetHeight() { - if ( chainActive.LastTip() != 0 ) - return chainActive.LastTip()->GetHeight(); + CBlockIndex *pindex; + if ( (pindex= chainActive.LastTip()) != 0 ) + return pindex->GetHeight(); else return(-1); } From 0a1234cb91a92fc5f4f7b9b0849f8e68bab0fb44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 01:41:54 -1100 Subject: [PATCH 014/659] Height 0 --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a772de50b..4e375d60d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -355,7 +355,7 @@ namespace { CBlockIndex *pindex; if ( (pindex= chainActive.LastTip()) != 0 ) return pindex->GetHeight(); - else return(-1); + else return(0); } void UpdatePreferredDownload(CNode* node, CNodeState* state) From efec2490c8c4835e030d7955b860298e64a1ac77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 01:48:03 -1100 Subject: [PATCH 015/659] pindexBestHeader!=0 --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 4e375d60d..df959bf76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8197,7 +8197,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pindexBestHeader!=0) { // Only actively request headers from a single peer, unless we're close to today. if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; From 119a7e825b4c5a57bbf8a078d8b1e8b30522e44c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 01:54:11 -1100 Subject: [PATCH 016/659] Make nSPV disable wallet --- src/init.cpp | 2 ++ src/main.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index d61426722..919a07e1d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1064,6 +1064,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) RegisterAllCoreRPCCommands(tableRPC); #ifdef ENABLE_WALLET bool fDisableWallet = GetBoolArg("-disablewallet", false); + if ( KOMODO_NSPV != 0 ) + fDisableWallet = true; if (!fDisableWallet) RegisterWalletRPCCommands(tableRPC); #endif diff --git a/src/main.cpp b/src/main.cpp index df959bf76..e9b23d4a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4109,7 +4109,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight(),true) != 0))) { #ifdef ENABLE_WALLET - if ( !GetBoolArg("-disablewallet", false) ) + if ( !GetBoolArg("-disablewallet", false) && KOMODO_NSPV == 0 ) pwalletMain->EraseFromWallet(tx.GetHash()); #endif } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ce377d094..955118346 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2955,7 +2955,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) uint64_t komodo_interestsum() { #ifdef ENABLE_WALLET - if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 && KOMODO_NSPV == 0 ) { uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime; vector vecOutputs; From 41ded8b8878ff4cf4f26acc90db146e9e2389037 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 02:04:11 -1100 Subject: [PATCH 017/659] SetRPCWarmupFinished(); uiInterface.InitMessage(_("Done loading")); --- src/init.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 919a07e1d..fb6eeaa8f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1483,6 +1483,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) std::vector vImportFiles; threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles)); StartNode(threadGroup, scheduler); + SetRPCWarmupFinished(); + uiInterface.InitMessage(_("Done loading")); return !fRequestShutdown; } // ********************************************************* Step 7: load block chain From 710c0fc9ffa151968786b95e684c0d7d0374744b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 02:16:44 -1100 Subject: [PATCH 018/659] InitBlockIndex(); --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index fb6eeaa8f..a17374ee1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1483,6 +1483,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) std::vector vImportFiles; threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles)); StartNode(threadGroup, scheduler); + InitBlockIndex(); SetRPCWarmupFinished(); uiInterface.InitMessage(_("Done loading")); return !fRequestShutdown; From 76318558411d4c3c700ab5b83bd69ba99bbca40a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 02:20:53 -1100 Subject: [PATCH 019/659] Check pblocktree --- src/main.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e9b23d4a7..148aa464e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6443,22 +6443,24 @@ bool InitBlockIndex() { { return true; } - // Use the provided setting for -txindex in the new database - fTxIndex = GetBoolArg("-txindex", true); - pblocktree->WriteFlag("txindex", fTxIndex); - // Use the provided setting for -addressindex in the new database - fAddressIndex = GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX); - pblocktree->WriteFlag("addressindex", fAddressIndex); - - // Use the provided setting for -timestampindex in the new database - fTimestampIndex = GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX); - pblocktree->WriteFlag("timestampindex", fTimestampIndex); - - fSpentIndex = GetBoolArg("-spentindex", DEFAULT_SPENTINDEX); - pblocktree->WriteFlag("spentindex", fSpentIndex); - fprintf(stderr,"fAddressIndex.%d/%d fSpentIndex.%d/%d\n",fAddressIndex,DEFAULT_ADDRESSINDEX,fSpentIndex,DEFAULT_SPENTINDEX); - LogPrintf("Initializing databases...\n"); - + if ( pblocktree != 0 ) + { + // Use the provided setting for -txindex in the new database + fTxIndex = GetBoolArg("-txindex", true); + pblocktree->WriteFlag("txindex", fTxIndex); + // Use the provided setting for -addressindex in the new database + fAddressIndex = GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX); + pblocktree->WriteFlag("addressindex", fAddressIndex); + + // Use the provided setting for -timestampindex in the new database + fTimestampIndex = GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX); + pblocktree->WriteFlag("timestampindex", fTimestampIndex); + + fSpentIndex = GetBoolArg("-spentindex", DEFAULT_SPENTINDEX); + pblocktree->WriteFlag("spentindex", fSpentIndex); + fprintf(stderr,"fAddressIndex.%d/%d fSpentIndex.%d/%d\n",fAddressIndex,DEFAULT_ADDRESSINDEX,fSpentIndex,DEFAULT_SPENTINDEX); + LogPrintf("Initializing databases...\n"); + } // Only add the genesis block if not reindexing (in which case we reuse the one already on disk) if (!fReindex) { try { From 6d09975752118b5252876e3a9a46828926ee6907 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 02:26:57 -1100 Subject: [PATCH 020/659] Skip asserts --- src/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 148aa464e..4b2ef1174 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4214,8 +4214,11 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * // Get the current commitment tree SproutMerkleTree oldSproutTree; SaplingMerkleTree oldSaplingTree; - assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), oldSproutTree)); - assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), oldSaplingTree)); + if ( KOMODO_NSPV == 0 ) + { + assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), oldSproutTree)); + assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), oldSaplingTree)); + } // Apply the block atomically to the chain state. int64_t nTime2 = GetTimeMicros(); nTimeReadFromDisk += nTime2 - nTime1; int64_t nTime3; From 4d6cd8f0b4df547c68adc532334b021f38797f8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 02:32:01 -1100 Subject: [PATCH 021/659] Skip nonvolatile --- src/main.cpp | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4b2ef1174..e41ea3cbb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4243,13 +4243,17 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * mapBlockSource.erase(pindexNew->GetBlockHash()); nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2; LogPrint("bench", " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001); - assert(view.Flush()); + if ( KOMODO_NSPV == 0 ) + assert(view.Flush()); } int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3; LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001); // Write the chain state to disk, if necessary. - if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED)) - return false; + if ( KOMODO_NSPV == 0 ) + { + if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED)) + return false; + } int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4; LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001); // Remove conflicting transactions from the mempool. @@ -4261,14 +4265,17 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * // Update chainActive & related variables. UpdateTip(pindexNew); - // Tell wallet about transactions that went from mempool - // to conflicted: - BOOST_FOREACH(const CTransaction &tx, txConflicted) { - SyncWithWallets(tx, NULL); - } - // ... and about transactions that got confirmed: - BOOST_FOREACH(const CTransaction &tx, pblock->vtx) { - SyncWithWallets(tx, pblock); + if ( KOMODO_NSPV == 0 ) + { + // Tell wallet about transactions that went from mempool + // to conflicted: + BOOST_FOREACH(const CTransaction &tx, txConflicted) { + SyncWithWallets(tx, NULL); + } + // ... and about transactions that got confirmed: + BOOST_FOREACH(const CTransaction &tx, pblock->vtx) { + SyncWithWallets(tx, pblock); + } } // Update cached incremental witnesses GetMainSignals().ChainTip(pindexNew, pblock, oldSproutTree, oldSaplingTree, true); @@ -4286,19 +4293,22 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * komodo_broadcast(pblock,8); else if ( ASSETCHAINS_SYMBOL[0] != 0 ) komodo_broadcast(pblock,4);*/ - if ( ASSETCHAINS_CBOPRET != 0 ) - komodo_pricesupdate(pindexNew->GetHeight(),pblock); - if ( ASSETCHAINS_SAPLING <= 0 && pindexNew->nTime > KOMODO_SAPLING_ACTIVATION - 24*3600 ) - komodo_activate_sapling(pindexNew); - if ( ASSETCHAINS_CC != 0 && KOMODO_SNAPSHOT_INTERVAL != 0 && (pindexNew->GetHeight() % KOMODO_SNAPSHOT_INTERVAL) == 0 && pindexNew->GetHeight() >= KOMODO_SNAPSHOT_INTERVAL ) + if ( KOMODO_NSPV == 0 ) { - uint64_t start = time(NULL); - if ( !komodo_dailysnapshot(pindexNew->GetHeight()) ) + if ( ASSETCHAINS_CBOPRET != 0 ) + komodo_pricesupdate(pindexNew->GetHeight(),pblock); + if ( ASSETCHAINS_SAPLING <= 0 && pindexNew->nTime > KOMODO_SAPLING_ACTIVATION - 24*3600 ) + komodo_activate_sapling(pindexNew); + if ( ASSETCHAINS_CC != 0 && KOMODO_SNAPSHOT_INTERVAL != 0 && (pindexNew->GetHeight() % KOMODO_SNAPSHOT_INTERVAL) == 0 && pindexNew->GetHeight() >= KOMODO_SNAPSHOT_INTERVAL ) { - fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); - StartShutdown(); + uint64_t start = time(NULL); + if ( !komodo_dailysnapshot(pindexNew->GetHeight()) ) + { + fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); + StartShutdown(); + } + fprintf(stderr, "snapshot completed in: %lu seconds\n", time(NULL)-start); } - fprintf(stderr, "snapshot completed in: %lu seconds\n", time(NULL)-start); } return true; } From 17552a08e522d9bfdc0a6c42a536170a157f258f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 02:36:11 -1100 Subject: [PATCH 022/659] pcoinsTip = new CCoinsViewCache(pcoinscatcher); --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index a17374ee1..ca8252f29 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1483,6 +1483,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) std::vector vImportFiles; threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles)); StartNode(threadGroup, scheduler); + pcoinsTip = new CCoinsViewCache(pcoinscatcher); InitBlockIndex(); SetRPCWarmupFinished(); uiInterface.InitMessage(_("Done loading")); From c779fa885a5160a47833086c9b3de1cae402d8b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 02:40:25 -1100 Subject: [PATCH 023/659] Skip flush state --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e41ea3cbb..96b8edabe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6494,7 +6494,9 @@ bool InitBlockIndex() { if (!ActivateBestChain(true, state, &block)) return error("LoadBlockIndex(): genesis block cannot be activated"); // Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data - return FlushStateToDisk(state, FLUSH_STATE_ALWAYS); + if ( KOMODO_NSPV == 0 ) + return FlushStateToDisk(state, FLUSH_STATE_ALWAYS); + else return(true); } catch (const std::runtime_error& e) { return error("LoadBlockIndex(): failed to initialize block database: %s", e.what()); } From cb3756eb078daeb4cd5fab22a290a4f6f4993416 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 02:46:30 -1100 Subject: [PATCH 024/659] Print --- src/main.cpp | 2 +- src/net.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 96b8edabe..95571edeb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7048,7 +7048,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { const CChainParams& chainparams = Params(); LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); - //fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); +fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); diff --git a/src/net.h b/src/net.h index b7975bfec..bc0352bd6 100644 --- a/src/net.h +++ b/src/net.h @@ -462,6 +462,7 @@ public: void PushMessage(const char* pszCommand) { + fprintf(stderr,"push.(%s)\n",pszCommand); try { BeginMessage(pszCommand); @@ -477,6 +478,7 @@ public: template void PushMessage(const char* pszCommand, const T1& a1) { + fprintf(stderr,"push.(%s)\n",pszCommand); try { BeginMessage(pszCommand); From 0d2030f2e64d2fff557b8bbf343597bd7669adfe Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 02:59:41 -1100 Subject: [PATCH 025/659] Skip connect block --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 95571edeb..fa7362bfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3378,6 +3378,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { CDiskBlockPos blockPos; const CChainParams& chainparams = Params(); + if ( KOMODO_NSPV != 0 ) + return(true); if ( KOMODO_STOPAT != 0 && pindex->GetHeight() > KOMODO_STOPAT ) return(false); //fprintf(stderr,"connectblock ht.%d\n",(int32_t)pindex->GetHeight()); From fa39db59b39d51eb334da66e556c2a473930b339 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 03:18:19 -1100 Subject: [PATCH 026/659] Bypass non-nSPV messages --- src/main.cpp | 215 ++++++++++++++++++++++++++------------------------- 1 file changed, 110 insertions(+), 105 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fa7362bfd..2f1280506 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7313,7 +7313,112 @@ fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32 if (pfrom->fOneShot) pfrom->fDisconnect = true; } + else if (strCommand == "ping") + { + if (pfrom->nVersion > BIP0031_VERSION) + { + uint64_t nonce = 0; + vRecv >> nonce; + // Echo the message back with the nonce. This allows for two useful features: + // + // 1) A remote node can quickly check if the connection is operational + // 2) Remote nodes can measure the latency of the network thread. If this node + // is overloaded it won't respond to pings quickly and the remote node can + // avoid sending us more work, like chain download requests. + // + // The nonce stops the remote getting confused between different pings: without + // it, if the remote node sends a ping once per second and this node takes 5 + // seconds to respond to each, the 5th ping the remote sends would appear to + // return very quickly. + pfrom->PushMessage("pong", nonce); + } + } + + + else if (strCommand == "pong") + { + int64_t pingUsecEnd = nTimeReceived; + uint64_t nonce = 0; + size_t nAvail = vRecv.in_avail(); + bool bPingFinished = false; + std::string sProblem; + + if (nAvail >= sizeof(nonce)) { + vRecv >> nonce; + + // Only process pong message if there is an outstanding ping (old ping without nonce should never pong) + if (pfrom->nPingNonceSent != 0) { + if (nonce == pfrom->nPingNonceSent) { + // Matching pong received, this ping is no longer outstanding + bPingFinished = true; + int64_t pingUsecTime = pingUsecEnd - pfrom->nPingUsecStart; + if (pingUsecTime > 0) { + // Successful ping time measurement, replace previous + pfrom->nPingUsecTime = pingUsecTime; + pfrom->nMinPingUsecTime = std::min(pfrom->nMinPingUsecTime, pingUsecTime); + } else { + // This should never happen + sProblem = "Timing mishap"; + } + } else { + // Nonce mismatches are normal when pings are overlapping + sProblem = "Nonce mismatch"; + if (nonce == 0) { + // This is most likely a bug in another implementation somewhere; cancel this ping + bPingFinished = true; + sProblem = "Nonce zero"; + } + } + } else { + sProblem = "Unsolicited pong without ping"; + } + } else { + // This is most likely a bug in another implementation somewhere; cancel this ping + bPingFinished = true; + sProblem = "Short payload"; + } + + if (!(sProblem.empty())) { + LogPrint("net", "pong peer=%d %s: %s, %x expected, %x received, %u bytes\n", + pfrom->id, + pfrom->cleanSubVer, + sProblem, + pfrom->nPingNonceSent, + nonce, + nAvail); + } + if (bPingFinished) { + pfrom->nPingNonceSent = 0; + } + } + // This asymmetric behavior for inbound and outbound connections was introduced + // to prevent a fingerprinting attack: an attacker can send specific fake addresses + // to users' AddrMan and later request them by sending getaddr messages. + // Making nodes which are behind NAT and can only make outgoing connections ignore + // the getaddr message mitigates the attack. + else if ((strCommand == "getaddr") && (pfrom->fInbound)) + { + // Only send one GetAddr response per connection to reduce resource waste + // and discourage addr stamping of INV announcements. + if (pfrom->fSentAddr) { + LogPrint("net", "Ignoring repeated \"getaddr\". peer=%d\n", pfrom->id); + return true; + } + pfrom->fSentAddr = true; + + pfrom->vAddrToSend.clear(); + vector vAddr = addrman.GetAddr(); + BOOST_FOREACH(const CAddress &addr, vAddr) + pfrom->PushAddress(addr); + } + + else if ( KOMODO_NSPV != 0 ) + { + // handle addressutxos, addresstxids, notarizations, ... messages + fprintf(stderr,"ignore message %s\n",strCommand); + return; + } else if (strCommand == "inv") { @@ -7726,28 +7831,6 @@ fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32 } - // This asymmetric behavior for inbound and outbound connections was introduced - // to prevent a fingerprinting attack: an attacker can send specific fake addresses - // to users' AddrMan and later request them by sending getaddr messages. - // Making nodes which are behind NAT and can only make outgoing connections ignore - // the getaddr message mitigates the attack. - else if ((strCommand == "getaddr") && (pfrom->fInbound)) - { - // Only send one GetAddr response per connection to reduce resource waste - // and discourage addr stamping of INV announcements. - if (pfrom->fSentAddr) { - LogPrint("net", "Ignoring repeated \"getaddr\". peer=%d\n", pfrom->id); - return true; - } - pfrom->fSentAddr = true; - - pfrom->vAddrToSend.clear(); - vector vAddr = addrman.GetAddr(); - BOOST_FOREACH(const CAddress &addr, vAddr) - pfrom->PushAddress(addr); - } - - else if (strCommand == "mempool") { LOCK2(cs_main, pfrom->cs_filter); @@ -7772,88 +7855,6 @@ fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32 if (vInv.size() > 0) pfrom->PushMessage("inv", vInv); } - - - else if (strCommand == "ping") - { - if (pfrom->nVersion > BIP0031_VERSION) - { - uint64_t nonce = 0; - vRecv >> nonce; - // Echo the message back with the nonce. This allows for two useful features: - // - // 1) A remote node can quickly check if the connection is operational - // 2) Remote nodes can measure the latency of the network thread. If this node - // is overloaded it won't respond to pings quickly and the remote node can - // avoid sending us more work, like chain download requests. - // - // The nonce stops the remote getting confused between different pings: without - // it, if the remote node sends a ping once per second and this node takes 5 - // seconds to respond to each, the 5th ping the remote sends would appear to - // return very quickly. - pfrom->PushMessage("pong", nonce); - } - } - - - else if (strCommand == "pong") - { - int64_t pingUsecEnd = nTimeReceived; - uint64_t nonce = 0; - size_t nAvail = vRecv.in_avail(); - bool bPingFinished = false; - std::string sProblem; - - if (nAvail >= sizeof(nonce)) { - vRecv >> nonce; - - // Only process pong message if there is an outstanding ping (old ping without nonce should never pong) - if (pfrom->nPingNonceSent != 0) { - if (nonce == pfrom->nPingNonceSent) { - // Matching pong received, this ping is no longer outstanding - bPingFinished = true; - int64_t pingUsecTime = pingUsecEnd - pfrom->nPingUsecStart; - if (pingUsecTime > 0) { - // Successful ping time measurement, replace previous - pfrom->nPingUsecTime = pingUsecTime; - pfrom->nMinPingUsecTime = std::min(pfrom->nMinPingUsecTime, pingUsecTime); - } else { - // This should never happen - sProblem = "Timing mishap"; - } - } else { - // Nonce mismatches are normal when pings are overlapping - sProblem = "Nonce mismatch"; - if (nonce == 0) { - // This is most likely a bug in another implementation somewhere; cancel this ping - bPingFinished = true; - sProblem = "Nonce zero"; - } - } - } else { - sProblem = "Unsolicited pong without ping"; - } - } else { - // This is most likely a bug in another implementation somewhere; cancel this ping - bPingFinished = true; - sProblem = "Short payload"; - } - - if (!(sProblem.empty())) { - LogPrint("net", "pong peer=%d %s: %s, %x expected, %x received, %u bytes\n", - pfrom->id, - pfrom->cleanSubVer, - sProblem, - pfrom->nPingNonceSent, - nonce, - nAvail); - } - if (bPingFinished) { - pfrom->nPingNonceSent = 0; - } - } - - else if (fAlerts && strCommand == "alert") { CAlert alert; @@ -8207,7 +8208,11 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } state.fShouldBan = false; } - + if ( KOMODO_NSPV != 0 ) + { + // issue getaddressutxos, ... + return(true); + } BOOST_FOREACH(const CBlockReject& reject, state.rejects) pto->PushMessage("reject", (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock); state.rejects.clear(); From 4e22554ad3e7e35982c3bf081bfc42942a4652f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 03:20:52 -1100 Subject: [PATCH 027/659] Syntax --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2f1280506..8a0975d7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7416,8 +7416,8 @@ fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32 else if ( KOMODO_NSPV != 0 ) { // handle addressutxos, addresstxids, notarizations, ... messages - fprintf(stderr,"ignore message %s\n",strCommand); - return; + fprintf(stderr,"ignore message %s\n",strCommand.c_str()); + return(true); } else if (strCommand == "inv") From e7cd541cf195bd0cf804b4ba0ce4b4a8b1ed03ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 03:32:24 -1100 Subject: [PATCH 028/659] nServices bits NODE_ADDRINDEX and NODE_SPENTINDEX --- src/init.cpp | 7 +++++++ src/protocol.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index ca8252f29..0e770d3a8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1065,7 +1065,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) #ifdef ENABLE_WALLET bool fDisableWallet = GetBoolArg("-disablewallet", false); if ( KOMODO_NSPV != 0 ) + { fDisableWallet = true; + nLocalServices &= ~NODE_NETWORK; + } if (!fDisableWallet) RegisterWalletRPCCommands(tableRPC); #endif @@ -1901,6 +1904,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) PruneAndFlush(); } } + if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) != 0 ) + nLocalServices |= NODE_ADDRINDEX; + if ( GetBoolArg("-spentindex", DEFAULT_SPENTINDEX) != 0 ) + nLocalServices |= NODE_SPENTINDEX; // ********************************************************* Step 10: import blocks diff --git a/src/protocol.h b/src/protocol.h index d2a3cf556..6b1536d6f 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -91,6 +91,9 @@ enum { // but no longer do as of protocol version 170004 (= NO_BLOOM_VERSION) NODE_BLOOM = (1 << 2), + NODE_ADDRINDEX = (1 << 30), + NODE_SPENTINDEX = (1 << 29), + // Bits 24-31 are reserved for temporary experiments. Just pick a bit that // isn't getting used, or one not being used much, and notify the // bitcoin-development mailing list. Remember that service bits are just From a0990a8c06d93efcdb09f51e16b1c84fe401ab52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 04:10:48 -1100 Subject: [PATCH 029/659] +prints --- src/init.cpp | 2 +- src/main.cpp | 34 ++++++++++++++++++++++++++++++---- src/net.cpp | 1 + 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 0e770d3a8..a31ec56bd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1908,7 +1908,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) nLocalServices |= NODE_ADDRINDEX; if ( GetBoolArg("-spentindex", DEFAULT_SPENTINDEX) != 0 ) nLocalServices |= NODE_SPENTINDEX; - +fprintf(stderr,"nLocalServices %llx %d, %d\n",(long long)nLocalServices,GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)); // ********************************************************* Step 10: import blocks if (mapArgs.count("-blocknotify")) diff --git a/src/main.cpp b/src/main.cpp index 8a0975d7c..1d5258a58 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7046,6 +7046,21 @@ void static ProcessGetData(CNode* pfrom) } } +void komodo_nSPVreq(CNode *pfrom,std::vector payload) // received a request +{ + +} + +void komodo_nSPVresp(CNode *pfrom,std::vector payload) // received a response +{ + +} + +void komodo_nSPV(CNode *pto) // issue nSPV requests if has nServices +{ + +} + bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived) { const CChainParams& chainparams = Params(); @@ -7209,7 +7224,6 @@ fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32 } else if ( strCommand == "events" ) { - int32_t i; if ( ASSETCHAINS_CCLIB != "gamescc" ) { Misbehaving(pfrom->GetId(), 1); @@ -7412,10 +7426,22 @@ fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32 BOOST_FOREACH(const CAddress &addr, vAddr) pfrom->PushAddress(addr); } - + else if (strCommand == "getnSPV") + { + std::vector payload; + vRecv >> payload; + komodo_nSPVreq(pfrom,payload); + return(true); + } else if ( KOMODO_NSPV != 0 ) { - // handle addressutxos, addresstxids, notarizations, ... messages + if (strCommand == "nSPV") + { + std::vector payload; + vRecv >> payload; + komodo_nSPVresp(pfrom,payload); + return(true); + } fprintf(stderr,"ignore message %s\n",strCommand.c_str()); return(true); } @@ -8210,7 +8236,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } if ( KOMODO_NSPV != 0 ) { - // issue getaddressutxos, ... + komodo_nSPV(pto); return(true); } BOOST_FOREACH(const CBlockReject& reject, state.rejects) diff --git a/src/net.cpp b/src/net.cpp index 83dc0782e..98d7d67bb 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -458,6 +458,7 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); + fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); } From aa1c651a74e67179a01741e738195f0aa2c8fd06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 04:25:54 -1100 Subject: [PATCH 030/659] komodo_nSPV.h --- src/komodo_nSPV.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 15 +------------ src/net.cpp | 2 +- 3 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 src/komodo_nSPV.h diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h new file mode 100644 index 000000000..133dcee48 --- /dev/null +++ b/src/komodo_nSPV.h @@ -0,0 +1,57 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2014 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef KOMODO_NSPV_H +#define KOMODO_NSPV_H + +void komodo_nSPVreq(CNode *pfrom,std::vector payload) // received a request +{ + +} + +void komodo_nSPVresp(CNode *pfrom,std::vector payload) // received a response +{ + +} + +/*void komodo_sendnSPV(int32_t minpeers,int32_t maxpeers,const char *message,std::vector payload) +{ + int32_t numsent = 0; + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes) + { + if ( pnode->hSocket == INVALID_SOCKET ) + continue; + if ( numsent < minpeers || (rand() % 10) == 0 ) + { + //fprintf(stderr,"pushmessage\n"); + pnode->PushMessage(message,payload); + if ( numsent++ > maxpeers ) + break; + } + } +}*/ + +void komodo_nSPV(CNode *pto) // issue nSPV requests if has nServices +{ + +} + +#endif // KOMODO_NSPV_H diff --git a/src/main.cpp b/src/main.cpp index 1d5258a58..61f282541 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7046,20 +7046,7 @@ void static ProcessGetData(CNode* pfrom) } } -void komodo_nSPVreq(CNode *pfrom,std::vector payload) // received a request -{ - -} - -void komodo_nSPVresp(CNode *pfrom,std::vector payload) // received a response -{ - -} - -void komodo_nSPV(CNode *pto) // issue nSPV requests if has nServices -{ - -} +#include "komodo_nSPV.h" bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived) { diff --git a/src/net.cpp b/src/net.cpp index 98d7d67bb..7181f8a95 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -458,7 +458,7 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); - fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); +fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); } From d15bfa2bd318951c1fffe1cd58ebdb8c1c782e4e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 04:58:27 -1100 Subject: [PATCH 031/659] Stub messages --- src/init.cpp | 2 +- src/komodo_nSPV.h | 73 +++++++++++++++++++++++++++++++++-------------- src/net.cpp | 2 +- 3 files changed, 54 insertions(+), 23 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index a31ec56bd..7e131b759 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1067,7 +1067,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if ( KOMODO_NSPV != 0 ) { fDisableWallet = true; - nLocalServices &= ~NODE_NETWORK; + nLocalServices = 0; } if (!fDisableWallet) RegisterWalletRPCCommands(tableRPC); diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 133dcee48..7be895f83 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -21,37 +21,68 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -void komodo_nSPVreq(CNode *pfrom,std::vector payload) // received a request -{ - -} +#define NSPV_INFO 0x00 +#define NSPV_INFORESP 0x01 +#define NSPV_UTXOS 0x02 +#define NSPV_UTXOSRESP 0x03 -void komodo_nSPVresp(CNode *pfrom,std::vector payload) // received a response -{ - -} -/*void komodo_sendnSPV(int32_t minpeers,int32_t maxpeers,const char *message,std::vector payload) +void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request { - int32_t numsent = 0; - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) + int32_t len; std::vector response; + if ( (len= request.size()) > 0 ) { - if ( pnode->hSocket == INVALID_SOCKET ) - continue; - if ( numsent < minpeers || (rand() % 10) == 0 ) + response.resize(1); + if ( len == 1 && request[0] == NSPV_INFO ) // info { - //fprintf(stderr,"pushmessage\n"); - pnode->PushMessage(message,payload); - if ( numsent++ > maxpeers ) + response[0] = NSPV_INFORESP; + pnode->PushMessage("nSPV",response); + } + else if ( request[0] == NSPV_UTXOS ) + { + response[0] = NSPV_UTXOSRESP; + pnode->PushMessage("nSPV",response); + } + } +} + +void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response +{ + int32_t len; + if ( (len= response.size()) > 0 ) + { + switch ( response[0] ) + { + case NSPV_INFORESP: + fprintf(stderr,"got info response\n"); + break; + case NSPV_UTXOSRESP: + fprintf(stderr,"got utxos response\n"); + break; + default: fprintf(stderr,"unexpected response %02x size.%d\n",response[0],(int32_t)response.size()); break; } } -}*/ +} -void komodo_nSPV(CNode *pto) // issue nSPV requests if has nServices +void komodo_nSPV(CNode *pto) { - + std::vector request; + // limit frequency! + if ( (pto->nServices & NODE_ADDRINDEX) != 0 ) + { + // get utxo since lastheight + payload.resize(1); + payload[0] = NSPV_UTXOS; + pnode->PushMessage("getnSPV",request); + } + else + { + // query current height, blockhash, notarization info + payload.resize(1); + payload[0] = NSPV_INFO; + pnode->PushMessage("getnSPV",request); + } } #endif // KOMODO_NSPV_H diff --git a/src/net.cpp b/src/net.cpp index 7181f8a95..1e5f11ee0 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -458,7 +458,7 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); -fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); +//fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); } From 4478c3f3dfe724945ea9c5c39d1f12f53853bcb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 05:00:32 -1100 Subject: [PATCH 032/659] Syntax --- src/komodo_nSPV.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 7be895f83..2fdd8a88f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -36,12 +36,12 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( len == 1 && request[0] == NSPV_INFO ) // info { response[0] = NSPV_INFORESP; - pnode->PushMessage("nSPV",response); + pfrom->PushMessage("nSPV",response); } else if ( request[0] == NSPV_UTXOS ) { response[0] = NSPV_UTXOSRESP; - pnode->PushMessage("nSPV",response); + pfrom->PushMessage("nSPV",response); } } } @@ -72,15 +72,15 @@ void komodo_nSPV(CNode *pto) if ( (pto->nServices & NODE_ADDRINDEX) != 0 ) { // get utxo since lastheight - payload.resize(1); - payload[0] = NSPV_UTXOS; + request.resize(1); + request[0] = NSPV_UTXOS; pnode->PushMessage("getnSPV",request); } else { // query current height, blockhash, notarization info - payload.resize(1); - payload[0] = NSPV_INFO; + request.resize(1); + request[0] = NSPV_INFO; pnode->PushMessage("getnSPV",request); } } From 4411270346715fc07cb82d30bf70bc5fe72c08ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 05:01:46 -1100 Subject: [PATCH 033/659] Pto --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 2fdd8a88f..6d2efcac2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -74,14 +74,14 @@ void komodo_nSPV(CNode *pto) // get utxo since lastheight request.resize(1); request[0] = NSPV_UTXOS; - pnode->PushMessage("getnSPV",request); + pto->PushMessage("getnSPV",request); } else { // query current height, blockhash, notarization info request.resize(1); request[0] = NSPV_INFO; - pnode->PushMessage("getnSPV",request); + pto->PushMessage("getnSPV",request); } } From 4b876b61188674924ee51ac1156b04069cbaf65a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 05:30:56 -1100 Subject: [PATCH 034/659] Throttle rate of nSPV requests --- src/komodo_nSPV.h | 53 +++++++++++++++++++++++++++++++++-------------- src/net.h | 1 + 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 6d2efcac2..bb796b167 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -26,22 +26,31 @@ #define NSPV_UTXOS 0x02 #define NSPV_UTXOSRESP 0x03 +uint32_t NSPV_lastinfo,NSPV_lastutxos; void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request { - int32_t len; std::vector response; + int32_t len; std::vector response; uint32_t timestamp = time(NULL); if ( (len= request.size()) > 0 ) { response.resize(1); if ( len == 1 && request[0] == NSPV_INFO ) // info { - response[0] = NSPV_INFORESP; - pfrom->PushMessage("nSPV",response); + if ( timestamp > pfrom->lastinfo + KOMODO_BLOCKTIME/2 ) + { + response[0] = NSPV_INFORESP; + pfrom->lastinfo = timestamp; + pfrom->PushMessage("nSPV",response); + } } else if ( request[0] == NSPV_UTXOS ) { - response[0] = NSPV_UTXOSRESP; - pfrom->PushMessage("nSPV",response); + if ( timestamp > pfrom->lastutxos + KOMODO_BLOCKTIME/2 ) + { + response[0] = NSPV_UTXOSRESP; + pfrom->lastutxos = timestamp; + pfrom->PushMessage("nSPV",response); + } } } } @@ -67,21 +76,33 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r void komodo_nSPV(CNode *pto) { - std::vector request; + std::vector request; uint32_t timestamp = time(NULL); // limit frequency! - if ( (pto->nServices & NODE_ADDRINDEX) != 0 ) + if ( timestamp > NSPV_lastutxos + KOMODO_BLOCKTIME/2 ) { - // get utxo since lastheight - request.resize(1); - request[0] = NSPV_UTXOS; - pto->PushMessage("getnSPV",request); + if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > ptr->lastutxos + KOMODO_BLOCKTIME ) + { + // get utxo since lastheight + if ( (rand() % 100) < 10 ) + { + request.resize(1); + request[0] = NSPV_UTXOS; + NSPV_lastutxos = pto->lastutxos = timestamp; + pto->PushMessage("getnSPV",request); + return; + } + } } - else + if ( timestamp > NSPV_lastinfo + KOMODO_BLOCKTIME/2 && timestamp > ptr->lastinfo + KOMODO_BLOCKTIME ) { - // query current height, blockhash, notarization info - request.resize(1); - request[0] = NSPV_INFO; - pto->PushMessage("getnSPV",request); + if ( (rand() % 100) < 10 ) + { + // query current height, blockhash, notarization info + request.resize(1); + request[0] = NSPV_INFO; + NSPV_lastinfo = pto->lastinfo = timestamp; + pto->PushMessage("getnSPV",request); + } } } diff --git a/src/net.h b/src/net.h index bc0352bd6..fbe756c85 100644 --- a/src/net.h +++ b/src/net.h @@ -204,6 +204,7 @@ public: bool fWhitelisted; double dPingTime; double dPingWait; + uint32_t lastutxos,lastinfo; std::string addrLocal; }; From 49a7008f95b7c6e13486dc926ec2f4f9745f8949 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 05:46:07 -1100 Subject: [PATCH 035/659] NSPV_lastinfo --- src/komodo_nSPV.h | 23 ++++++++++++++--------- src/net.cpp | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index bb796b167..6ce3d5094 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -26,6 +26,9 @@ #define NSPV_UTXOS 0x02 #define NSPV_UTXOSRESP 0x03 +uint32_t CNode_lastinfo(CNode *pnode,uint32_t lastutxos); +uint32_t CNode_lastutxos(CNode *pnode,uint32_t lastutxos); + uint32_t NSPV_lastinfo,NSPV_lastutxos; void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request @@ -36,19 +39,19 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req response.resize(1); if ( len == 1 && request[0] == NSPV_INFO ) // info { - if ( timestamp > pfrom->lastinfo + KOMODO_BLOCKTIME/2 ) + if ( timestamp > CNode_lastinfo(pfrom,0) + ASSETCHAINS_BLOCKTIME/2 ) { response[0] = NSPV_INFORESP; - pfrom->lastinfo = timestamp; + CNode_lastinfo(pfrom,timestamp); pfrom->PushMessage("nSPV",response); } } else if ( request[0] == NSPV_UTXOS ) { - if ( timestamp > pfrom->lastutxos + KOMODO_BLOCKTIME/2 ) + if ( timestamp > CNode_lastutxos(pfrom,0) + ASSETCHAINS_BLOCKTIME/2 ) { response[0] = NSPV_UTXOSRESP; - pfrom->lastutxos = timestamp; + CNode_lastutxos(pfrom,timestamp); pfrom->PushMessage("nSPV",response); } } @@ -78,29 +81,31 @@ void komodo_nSPV(CNode *pto) { std::vector request; uint32_t timestamp = time(NULL); // limit frequency! - if ( timestamp > NSPV_lastutxos + KOMODO_BLOCKTIME/2 ) + if ( timestamp > NSPV_lastutxos + ASSETCHAINS_BLOCKTIME/2 ) { - if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > ptr->lastutxos + KOMODO_BLOCKTIME ) + if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > CNode_lastutxos(pto,0) + ASSETCHAINS_BLOCKTIME ) { // get utxo since lastheight if ( (rand() % 100) < 10 ) { request.resize(1); request[0] = NSPV_UTXOS; - NSPV_lastutxos = pto->lastutxos = timestamp; + NSPV_lastutxos = timestamp; + CNode_lastutxos(pto,NSPV_lastutxos); pto->PushMessage("getnSPV",request); return; } } } - if ( timestamp > NSPV_lastinfo + KOMODO_BLOCKTIME/2 && timestamp > ptr->lastinfo + KOMODO_BLOCKTIME ) + if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > CNode_lastinfo(pto,0) + ASSETCHAINS_BLOCKTIME ) { if ( (rand() % 100) < 10 ) { // query current height, blockhash, notarization info request.resize(1); request[0] = NSPV_INFO; - NSPV_lastinfo = pto->lastinfo = timestamp; + NSPV_lastinfo = timestamp; + CNode_lastinfo(pto,NSPV_lastinfo); pto->PushMessage("getnSPV",request); } } diff --git a/src/net.cpp b/src/net.cpp index 1e5f11ee0..f82e69e9d 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -684,8 +684,21 @@ int CNetMessage::readData(const char *pch, unsigned int nBytes) +uint32_t CNode_lastutxos(CNode *pnode,uint32_t lastutxos) +{ + uint32_t prev = pnode->lastutxos; + if ( lastutxos != 0 ) + pnode->lastutxos = lastutxos; + return(prev); +} - +uint32_t CNode_lastinfo(CNode *pnode,uint32_t lastinfo) +{ + uint32_t prev = pnode->lastinfo; + if ( lastinfo != 0 ) + pnode->lastinfo = lastinfo; + return(prev); +} // requires LOCK(cs_vSend) From e9a271444194db68576ee5ff050fcf1c8ea5caaa Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 05:49:14 -1100 Subject: [PATCH 036/659] uint32_t lastutxos,lastinfo; --- src/komodo_nSPV.h | 21 ++++++++------------- src/net.cpp | 19 ------------------- src/net.h | 2 +- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 6ce3d5094..680949b12 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -26,9 +26,6 @@ #define NSPV_UTXOS 0x02 #define NSPV_UTXOSRESP 0x03 -uint32_t CNode_lastinfo(CNode *pnode,uint32_t lastutxos); -uint32_t CNode_lastutxos(CNode *pnode,uint32_t lastutxos); - uint32_t NSPV_lastinfo,NSPV_lastutxos; void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request @@ -39,19 +36,19 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req response.resize(1); if ( len == 1 && request[0] == NSPV_INFO ) // info { - if ( timestamp > CNode_lastinfo(pfrom,0) + ASSETCHAINS_BLOCKTIME/2 ) + if ( timestamp > pfrom->lastinfo + ASSETCHAINS_BLOCKTIME/2 ) { response[0] = NSPV_INFORESP; - CNode_lastinfo(pfrom,timestamp); + pfrom->lastinfo = timestamp; pfrom->PushMessage("nSPV",response); } } else if ( request[0] == NSPV_UTXOS ) { - if ( timestamp > CNode_lastutxos(pfrom,0) + ASSETCHAINS_BLOCKTIME/2 ) + if ( timestamp > pfrom->lastutxos + ASSETCHAINS_BLOCKTIME/2 ) { response[0] = NSPV_UTXOSRESP; - CNode_lastutxos(pfrom,timestamp); + pfrom->lastutxos = timestamp; pfrom->PushMessage("nSPV",response); } } @@ -83,29 +80,27 @@ void komodo_nSPV(CNode *pto) // limit frequency! if ( timestamp > NSPV_lastutxos + ASSETCHAINS_BLOCKTIME/2 ) { - if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > CNode_lastutxos(pto,0) + ASSETCHAINS_BLOCKTIME ) + if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > ptr->lastutxos + ASSETCHAINS_BLOCKTIME ) { // get utxo since lastheight if ( (rand() % 100) < 10 ) { request.resize(1); request[0] = NSPV_UTXOS; - NSPV_lastutxos = timestamp; - CNode_lastutxos(pto,NSPV_lastutxos); + NSPV_lastutxos = pto->lastutxos = timestamp; pto->PushMessage("getnSPV",request); return; } } } - if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > CNode_lastinfo(pto,0) + ASSETCHAINS_BLOCKTIME ) + if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > ptr->lastinfo + ASSETCHAINS_BLOCKTIME ) { if ( (rand() % 100) < 10 ) { // query current height, blockhash, notarization info request.resize(1); request[0] = NSPV_INFO; - NSPV_lastinfo = timestamp; - CNode_lastinfo(pto,NSPV_lastinfo); + NSPV_lastinfo = pto->lastinfo = timestamp; pto->PushMessage("getnSPV",request); } } diff --git a/src/net.cpp b/src/net.cpp index f82e69e9d..5806489a8 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -682,25 +682,6 @@ int CNetMessage::readData(const char *pch, unsigned int nBytes) - - -uint32_t CNode_lastutxos(CNode *pnode,uint32_t lastutxos) -{ - uint32_t prev = pnode->lastutxos; - if ( lastutxos != 0 ) - pnode->lastutxos = lastutxos; - return(prev); -} - -uint32_t CNode_lastinfo(CNode *pnode,uint32_t lastinfo) -{ - uint32_t prev = pnode->lastinfo; - if ( lastinfo != 0 ) - pnode->lastinfo = lastinfo; - return(prev); -} - - // requires LOCK(cs_vSend) void SocketSendData(CNode *pnode) { diff --git a/src/net.h b/src/net.h index fbe756c85..c50d31f6a 100644 --- a/src/net.h +++ b/src/net.h @@ -204,7 +204,6 @@ public: bool fWhitelisted; double dPingTime; double dPingWait; - uint32_t lastutxos,lastinfo; std::string addrLocal; }; @@ -277,6 +276,7 @@ public: int64_t nLastRecv; int64_t nTimeConnected; int64_t nTimeOffset; + uint32_t lastutxos,lastinfo; CAddress addr; std::string addrName; CService addrLocal; From 52c78a5d796667cf9df8ee17e0c3ae54af16938b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 05:54:10 -1100 Subject: [PATCH 037/659] Pto --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 680949b12..bb5ddeefd 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -80,7 +80,7 @@ void komodo_nSPV(CNode *pto) // limit frequency! if ( timestamp > NSPV_lastutxos + ASSETCHAINS_BLOCKTIME/2 ) { - if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > ptr->lastutxos + ASSETCHAINS_BLOCKTIME ) + if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > pto->lastutxos + ASSETCHAINS_BLOCKTIME ) { // get utxo since lastheight if ( (rand() % 100) < 10 ) @@ -93,7 +93,7 @@ void komodo_nSPV(CNode *pto) } } } - if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > ptr->lastinfo + ASSETCHAINS_BLOCKTIME ) + if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->lastinfo + ASSETCHAINS_BLOCKTIME ) { if ( (rand() % 100) < 10 ) { From e28d1005beee1b50d430ed03c0584f17c7d934cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 06:43:05 -1100 Subject: [PATCH 038/659] Rest of nSPV function stubs --- src/komodo_nSPV.h | 142 +++++++++++++++++++++++++++++++++++++++++++--- src/net.h | 2 +- 2 files changed, 134 insertions(+), 10 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index bb5ddeefd..c43c7b991 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -25,8 +25,65 @@ #define NSPV_INFORESP 0x01 #define NSPV_UTXOS 0x02 #define NSPV_UTXOSRESP 0x03 +#define NSPV_NTZS 0x04 +#define NSPV_NTZSRESP 0x05 +#define NSPV_NTZPROOF 0x06 +#define NSPV_NTZPROOFRESP 0x07 +#define NSPV_TXPROOF 0x08 +#define NSPV_TXPROOFRESP 0x09 + +struct NSPV_ntz +{ + uint256 blockhash,txid,othertxid; + int32_t height,txidheight; +}; + +struct NSPV_info +{ + struct NSPV_ntz notarization; + uint256 blockhash; + int32_t height; +}; + +struct NSPV_utxo +{ + uint256 txid; + int64_t satoshis,extradata; + int32_t vout,height; +}; + +struct NSPV_ntzs +{ + struct NSPV_ntz before,after; +}; + +struct NSPV_ntzproofhdr +{ + std::vector headers; + int32_t beforeheight,afterheight; +}; + +struct NSPV_ntzproof +{ + struct NSPV_ntzproofhdr hdr; + std::vector beforentz,afterntz; +}; + +struct NSPV_MMRproof +{ + struct NSPV_ntzproofhdr hdr; + std::vector mmrproof; +}; + +struct NSPV_txproof +{ + uint256 txid; + std::vector tx,txproof; + int32_t height; +}; uint32_t NSPV_lastinfo,NSPV_lastutxos; +std::vector NSPV_utxos; void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request { @@ -52,23 +109,59 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req pfrom->PushMessage("nSPV",response); } } - } + else if ( request[0] == NSPV_NTZS ) + { + if ( timestamp > pfrom->lastntzs ) + { + response[0] = NSPV_NTZSRESP; + pfrom->lastntzs = timestamp; + pfrom->PushMessage("nSPV",response); + } + } + else if ( request[0] == NSPV_NTZPROOF ) + { + if ( timestamp > pfrom->lastproof ) + { + response[0] = NSPV_NTZPROOFRESP; + pfrom->lastproof = timestamp; + pfrom->PushMessage("nSPV",response); + } + } + else if ( request[0] == NSPV_TXPROOF ) + { + if ( timestamp > pfrom->lastproof ) + { + response[0] = NSPV_TXPROOFRESP; + pfrom->lastproof = timestamp; + pfrom->PushMessage("nSPV",response); + } + } + } } void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response { - int32_t len; + int32_t len; uint32_t timestamp = (uin32_t)time(NULL); if ( (len= response.size()) > 0 ) { switch ( response[0] ) { case NSPV_INFORESP: - fprintf(stderr,"got info response\n"); + fprintf(stderr,"got info response %u\n",timestamp); // update current height and ntrz status break; case NSPV_UTXOSRESP: - fprintf(stderr,"got utxos response\n"); - break; - default: fprintf(stderr,"unexpected response %02x size.%d\n",response[0],(int32_t)response.size()); + fprintf(stderr,"got utxos response %u\n",timestamp); // update utxos list + break; + case NSPV_NTZSRESP: + fprintf(stderr,"got ntzs response %u\n",timestamp); // update utxos[i] + break; + case NSPV_NTZPROOFRESP: + fprintf(stderr,"got ntzproof response %u\n",timestamp); // update utxos[i] + break; + case NSPV_TXPROOFRESP: + fprintf(stderr,"got txproof response %u\n",timestamp); // update utxos[i] + break; + default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); break; } } @@ -77,7 +170,39 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r void komodo_nSPV(CNode *pto) { std::vector request; uint32_t timestamp = time(NULL); - // limit frequency! + if ( timestamp > pto->lastntzs || timestamp > pto->lastproof ) + { + for (i=0; i pto->lastntzs ) + { + request[0] = NSPV_NTZS; + pto->lastntzs = timestamp; + pto->PushMessage("getnSPV",request); + return; + } + else if ( timestamp > pto->lastproof ) + { + if ( NSPV_utxos[i].tx.size() == 0 ) + { + request[0] = NSPV_TXPROOF; + pto->lastproof = timestamp; + pto->PushMessage("getnSPV",request); + } + else + { + request[0] = NSPV_NTZPROOF; + pto->lastproof = timestamp; + pto->PushMessage("getnSPV",request); + } + return; + } + } + } + } if ( timestamp > NSPV_lastutxos + ASSETCHAINS_BLOCKTIME/2 ) { if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > pto->lastutxos + ASSETCHAINS_BLOCKTIME ) @@ -89,13 +214,12 @@ void komodo_nSPV(CNode *pto) request[0] = NSPV_UTXOS; NSPV_lastutxos = pto->lastutxos = timestamp; pto->PushMessage("getnSPV",request); - return; } } } if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->lastinfo + ASSETCHAINS_BLOCKTIME ) { - if ( (rand() % 100) < 10 ) + if ( (rand() % 100) < 20 ) { // query current height, blockhash, notarization info request.resize(1); diff --git a/src/net.h b/src/net.h index c50d31f6a..3b9ad176f 100644 --- a/src/net.h +++ b/src/net.h @@ -276,7 +276,7 @@ public: int64_t nLastRecv; int64_t nTimeConnected; int64_t nTimeOffset; - uint32_t lastutxos,lastinfo; + uint32_t lastutxos,lastinfo,lastntzs,lastproof; CAddress addr; std::string addrName; CService addrLocal; From 550687d0c12054347b31bf22f9b843b9ffd4edac Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 06:54:35 -1100 Subject: [PATCH 039/659] NSPV_equiheader --- src/komodo_nSPV.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c43c7b991..c9399822a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -57,9 +57,21 @@ struct NSPV_ntzs struct NSPV_ntz before,after; }; +struct NSPV_equiheader +{ + int32_t nVersion; + uint256 hashPrevBlock; + uint256 hashMerkleRoot; + uint256 hashFinalSaplingRoot; + uint32_t nTime; + uint32_t nBits; + CPOSNonce nNonce; + uint8_t nSolution[1344]; +}; + struct NSPV_ntzproofhdr { - std::vector headers; + std::vector headers; int32_t beforeheight,afterheight; }; @@ -141,7 +153,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response { - int32_t len; uint32_t timestamp = (uin32_t)time(NULL); + int32_t len; uint32_t timestamp = (uint32_t)time(NULL); if ( (len= response.size()) > 0 ) { switch ( response[0] ) @@ -169,7 +181,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r void komodo_nSPV(CNode *pto) { - std::vector request; uint32_t timestamp = time(NULL); + std::vector request; int32_t i; uint32_t timestamp = time(NULL); if ( timestamp > pto->lastntzs || timestamp > pto->lastproof ) { for (i=0; i Date: Tue, 2 Jul 2019 06:58:29 -1100 Subject: [PATCH 040/659] Syntax --- src/komodo_nSPV.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c9399822a..1d2acb908 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -49,7 +49,8 @@ struct NSPV_utxo { uint256 txid; int64_t satoshis,extradata; - int32_t vout,height; + int32_t vout,height,before,after; + std::vector tx,txproof; }; struct NSPV_ntzs @@ -186,7 +187,7 @@ void komodo_nSPV(CNode *pto) { for (i=0; i pto->lastntzs ) @@ -204,7 +205,7 @@ void komodo_nSPV(CNode *pto) pto->lastproof = timestamp; pto->PushMessage("getnSPV",request); } - else + else // need space for the headers... { request[0] = NSPV_NTZPROOF; pto->lastproof = timestamp; From f016d63e5179ee8a97c6fd38870fc82328f7dcd5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 06:59:33 -1100 Subject: [PATCH 041/659] Syntax --- src/komodo_nSPV.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1d2acb908..e8bdb4a9e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -98,6 +98,7 @@ struct NSPV_txproof uint32_t NSPV_lastinfo,NSPV_lastutxos; std::vector NSPV_utxos; +// on fullnode: void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request { int32_t len; std::vector response; uint32_t timestamp = time(NULL); @@ -152,6 +153,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } } +// on nSPV client void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response { int32_t len; uint32_t timestamp = (uint32_t)time(NULL); From 73626347e2515aae9106511bdc4ea666a778fc6e Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Tue, 2 Jul 2019 20:05:29 +0200 Subject: [PATCH 042/659] change max ac_eras to 7 --- src/komodo_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 7be46f613..5074b4303 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -18,7 +18,7 @@ #include "komodo_nk.h" #define ASSETCHAINS_MINHEIGHT 128 -#define ASSETCHAINS_MAX_ERAS 3 +#define ASSETCHAINS_MAX_ERAS 7 #define KOMODO_ELECTION_GAP 2000 #define ROUNDROBIN_DELAY 61 #define KOMODO_ASSETCHAIN_MAXLEN 65 From 9edaca71f4ee6fd33b7fbbad693649b5d94fbcdc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 07:14:27 -1100 Subject: [PATCH 043/659] Remove rand throttle --- src/komodo_nSPV.h | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e8bdb4a9e..4b46c830a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -162,8 +162,8 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r switch ( response[0] ) { case NSPV_INFORESP: - fprintf(stderr,"got info response %u\n",timestamp); // update current height and ntrz status - break; + fprintf(stderr,"got info response %u\n",timestamp); // update current height and ntrz status + break; case NSPV_UTXOSRESP: fprintf(stderr,"got utxos response %u\n",timestamp); // update utxos list break; @@ -223,25 +223,19 @@ void komodo_nSPV(CNode *pto) if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > pto->lastutxos + ASSETCHAINS_BLOCKTIME ) { // get utxo since lastheight - if ( (rand() % 100) < 10 ) - { - request.resize(1); - request[0] = NSPV_UTXOS; - NSPV_lastutxos = pto->lastutxos = timestamp; - pto->PushMessage("getnSPV",request); - } + request.resize(1); + request[0] = NSPV_UTXOS; + NSPV_lastutxos = pto->lastutxos = timestamp; + pto->PushMessage("getnSPV",request); } } if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->lastinfo + ASSETCHAINS_BLOCKTIME ) { - if ( (rand() % 100) < 20 ) - { - // query current height, blockhash, notarization info - request.resize(1); - request[0] = NSPV_INFO; - NSPV_lastinfo = pto->lastinfo = timestamp; - pto->PushMessage("getnSPV",request); - } + // query current height, blockhash, notarization info + request.resize(1); + request[0] = NSPV_INFO; + NSPV_lastinfo = pto->lastinfo = timestamp; + pto->PushMessage("getnSPV",request); } } From a76d74fc648fe8b7ca5a6f5f52ad487d699be5b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 07:25:58 -1100 Subject: [PATCH 044/659] Revert rand skip --- src/komodo_nSPV.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4b46c830a..7fed4b206 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -223,19 +223,25 @@ void komodo_nSPV(CNode *pto) if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > pto->lastutxos + ASSETCHAINS_BLOCKTIME ) { // get utxo since lastheight - request.resize(1); - request[0] = NSPV_UTXOS; - NSPV_lastutxos = pto->lastutxos = timestamp; - pto->PushMessage("getnSPV",request); + if ( (rand() % 100) < 10 ) + { + request.resize(1); + request[0] = NSPV_UTXOS; + NSPV_lastutxos = pto->lastutxos = timestamp; + pto->PushMessage("getnSPV",request); + } } } if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->lastinfo + ASSETCHAINS_BLOCKTIME ) { - // query current height, blockhash, notarization info - request.resize(1); - request[0] = NSPV_INFO; - NSPV_lastinfo = pto->lastinfo = timestamp; - pto->PushMessage("getnSPV",request); + if ( (rand() % 100) < 10 ) + { + // query current height, blockhash, notarization info + request.resize(1); + request[0] = NSPV_INFO; + NSPV_lastinfo = pto->lastinfo = timestamp; + pto->PushMessage("getnSPV",request); + } } } From 0238f38686d73f504c16c15b46a06a14f99bc64b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 00:36:06 -1100 Subject: [PATCH 045/659] txid --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9a80e5e24..1006a9ada 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -652,6 +652,7 @@ const char *banned_txids[] = //"01d8c839463bda2f2f6400ede4611357913684927a767422a8560ead1b22557c", //"6e4980a9e1bd669f4df04732dc6f11b7773b6de88d1abcf89a6b9007d72ef9ac", //"6cc1d0495170bc0e11fd3925297623562e529ea1336b66ea61f8a1159041aed2", + //"250875424cece9bcd98cb226b09da7671625633d6958589e3a462bad89ad87cc", // missed }; int32_t komodo_checkvout(int32_t vout,int32_t k,int32_t indallvouts) From b876a9b92905cb51f488c2308ad23f139f034217 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 08:13:34 -1100 Subject: [PATCH 046/659] Cast uint32_t --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 7fed4b206..b8ed401bc 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -101,7 +101,7 @@ std::vector NSPV_utxos; // on fullnode: void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request { - int32_t len; std::vector response; uint32_t timestamp = time(NULL); + int32_t len; std::vector response; uint32_t timestamp = (uint32_t)time(NULL); if ( (len= request.size()) > 0 ) { response.resize(1); @@ -184,7 +184,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r void komodo_nSPV(CNode *pto) { - std::vector request; int32_t i; uint32_t timestamp = time(NULL); + std::vector request; int32_t i; uint32_t timestamp = (uint32_t)time(NULL); if ( timestamp > pto->lastntzs || timestamp > pto->lastproof ) { for (i=0; i Date: Tue, 2 Jul 2019 08:56:09 -1100 Subject: [PATCH 047/659] Create NODE_NSPV nServices flag --- src/komodo_nSPV.h | 2 ++ src/net.cpp | 2 +- src/protocol.cpp | 2 +- src/protocol.h | 5 +++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b8ed401bc..eec332102 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -185,6 +185,8 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r void komodo_nSPV(CNode *pto) { std::vector request; int32_t i; uint32_t timestamp = (uint32_t)time(NULL); + if ( (pto->nServices & NODE_NSPV) == 0 ) + return; if ( timestamp > pto->lastntzs || timestamp > pto->lastproof ) { for (i=0; i mapLocalHost; static bool vfLimited[NET_MAX] = {}; diff --git a/src/protocol.cpp b/src/protocol.cpp index c7d95f809..36ed63934 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -102,7 +102,7 @@ CAddress::CAddress(CService ipIn, uint64_t nServicesIn) : CService(ipIn) void CAddress::Init() { - nServices = NODE_NETWORK; + nServices = NODE_NETWORK | NODE_NSPV; nTime = 100000000; } diff --git a/src/protocol.h b/src/protocol.h index 6b1536d6f..b7ad483ac 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -91,8 +91,9 @@ enum { // but no longer do as of protocol version 170004 (= NO_BLOOM_VERSION) NODE_BLOOM = (1 << 2), - NODE_ADDRINDEX = (1 << 30), - NODE_SPENTINDEX = (1 << 29), + NODE_NSPV = (1 << 30), + NODE_ADDRINDEX = (1 << 29), + NODE_SPENTINDEX = (1 << 28), // Bits 24-31 are reserved for temporary experiments. Just pick a bit that // isn't getting used, or one not being used much, and notify the From 0dc11fbb0282da54b46a4e71642356aecff85a2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 09:16:11 -1100 Subject: [PATCH 048/659] Spent info rpc helper --- src/komodo_defs.h | 8 ++++++++ src/komodo_nSPV.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++- src/net.h | 2 +- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 6106a6000..49e247ae4 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -336,5 +336,13 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); int32_t komodo_currentheight(); +struct NSPV_spentinfo +{ + uint256 txid,spenttxid; + int32_t vout,height,spentvin,spentheight; +}; +void komodo_nSPV_spentinfoclear(); +struct nSPV_spentinfo komodo_nSPV_spentinfo(bits256 txid,int32_t vout); + #endif diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index eec332102..5ea5b106c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -31,6 +31,8 @@ #define NSPV_NTZPROOFRESP 0x07 #define NSPV_TXPROOF 0x08 #define NSPV_TXPROOFRESP 0x09 +#define NSPV_SPENTINFO 0x0a +#define NSPV_SPENTINFORESP 0x0b struct NSPV_ntz { @@ -97,6 +99,7 @@ struct NSPV_txproof uint32_t NSPV_lastinfo,NSPV_lastutxos; std::vector NSPV_utxos; +std::vector NSPV_spends; // on fullnode: void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request @@ -120,6 +123,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response[0] = NSPV_UTXOSRESP; pfrom->lastutxos = timestamp; + // check mempool pfrom->PushMessage("nSPV",response); } } @@ -150,7 +154,17 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req pfrom->PushMessage("nSPV",response); } } - } + else if ( request[0] == NSPV_SPENTINFO ) + { + if ( timestamp > pfrom->lastspent ) + { + response[0] = NSPV_SPENTINFORESP; + // check mempool + pfrom->lastspent = timestamp; + pfrom->PushMessage("nSPV",response); + } + } + } } // on nSPV client @@ -176,12 +190,47 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_TXPROOFRESP: fprintf(stderr,"got txproof response %u\n",timestamp); // update utxos[i] break; + case NSPV_SPENTINFORESP: + fprintf(stderr,"got spentinfo response %u\n",timestamp); // update utxos[i] + break; default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); break; } } } +void komodo_nSPV_spentinfoclear() +{ + nSPV_spends.resize(0); +} + +struct nSPV_spentinfo komodo_nSPV_spentinfo(bits256 txid,int32_t vout) // just a primitive example of how to add new rpc to p2p msg +{ + std::vector request; struct nSPV_spentinfo I; int32_t i,numsent = 0; uint32_t timestamp = (uint32_t)time(NULL); + // lookup spentinfo + for (i=0; ihSocket == INVALID_SOCKET ) + continue; + if ( (pto->nServices & NODE_NSPV) != 0 && timestamp > pto->lastspent ) + { + request.resize(1); + request[0] = NSPV_SPENTINFO; + pto->lastspent = timestamp; + pto->PushMessage("getnSPV",request); + if ( ++numsent >= 3 ) + break; + } + } +} + void komodo_nSPV(CNode *pto) { std::vector request; int32_t i; uint32_t timestamp = (uint32_t)time(NULL); diff --git a/src/net.h b/src/net.h index 3b9ad176f..dce52aa8b 100644 --- a/src/net.h +++ b/src/net.h @@ -276,7 +276,7 @@ public: int64_t nLastRecv; int64_t nTimeConnected; int64_t nTimeOffset; - uint32_t lastutxos,lastinfo,lastntzs,lastproof; + uint32_t lastutxos,lastinfo,lastntzs,lastproof,lastspent; CAddress addr; std::string addrName; CService addrLocal; From e3986e77a01abbf5a2bb8742b17b684a4eed1ceb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 09:17:27 -1100 Subject: [PATCH 049/659] Uint256 --- src/komodo_defs.h | 2 +- src/komodo_nSPV.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 49e247ae4..8cdfe1c59 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -342,7 +342,7 @@ struct NSPV_spentinfo int32_t vout,height,spentvin,spentheight; }; void komodo_nSPV_spentinfoclear(); -struct nSPV_spentinfo komodo_nSPV_spentinfo(bits256 txid,int32_t vout); +struct nSPV_spentinfo komodo_nSPV_spentinfo(uint256 txid,int32_t vout); #endif diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 5ea5b106c..e1964f887 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -204,7 +204,7 @@ void komodo_nSPV_spentinfoclear() nSPV_spends.resize(0); } -struct nSPV_spentinfo komodo_nSPV_spentinfo(bits256 txid,int32_t vout) // just a primitive example of how to add new rpc to p2p msg +struct nSPV_spentinfo komodo_nSPV_spentinfo(uint256 txid,int32_t vout) // just a primitive example of how to add new rpc to p2p msg { std::vector request; struct nSPV_spentinfo I; int32_t i,numsent = 0; uint32_t timestamp = (uint32_t)time(NULL); // lookup spentinfo From 347276f7765cca8c80ec1b242aa44955a7b3b02d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 09:24:44 -1100 Subject: [PATCH 050/659] Syntax --- src/komodo_nSPV.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e1964f887..95ddcd4d6 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -201,16 +201,16 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r void komodo_nSPV_spentinfoclear() { - nSPV_spends.resize(0); + NSPV_spends.resize(0); } struct nSPV_spentinfo komodo_nSPV_spentinfo(uint256 txid,int32_t vout) // just a primitive example of how to add new rpc to p2p msg { std::vector request; struct nSPV_spentinfo I; int32_t i,numsent = 0; uint32_t timestamp = (uint32_t)time(NULL); // lookup spentinfo - for (i=0; i Date: Tue, 2 Jul 2019 09:26:39 -1100 Subject: [PATCH 051/659] nSPV --- src/komodo_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 8cdfe1c59..8f32306d9 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -336,7 +336,7 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); int32_t komodo_currentheight(); -struct NSPV_spentinfo +struct nSPV_spentinfo { uint256 txid,spenttxid; int32_t vout,height,spentvin,spentheight; From c02de15ef2dcb255f62edefd7ed88a780c9dc6d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 09:37:20 -1100 Subject: [PATCH 052/659] NSPV --- src/komodo_defs.h | 6 +++--- src/komodo_nSPV.h | 6 +++--- src/main.cpp | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 8f32306d9..784502dc8 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -336,13 +336,13 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); int32_t komodo_currentheight(); -struct nSPV_spentinfo +struct NSPV_spentinfo { uint256 txid,spenttxid; int32_t vout,height,spentvin,spentheight; }; -void komodo_nSPV_spentinfoclear(); -struct nSPV_spentinfo komodo_nSPV_spentinfo(uint256 txid,int32_t vout); +void komodo_NSPV_spentinfoclear(); +struct NSPV_spentinfo komodo_NSPV_spentinfo(uint256 txid,int32_t vout); #endif diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 95ddcd4d6..4fde5b5e0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -199,14 +199,14 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r } } -void komodo_nSPV_spentinfoclear() +void komodo_NSPV_spentinfoclear() { NSPV_spends.resize(0); } -struct nSPV_spentinfo komodo_nSPV_spentinfo(uint256 txid,int32_t vout) // just a primitive example of how to add new rpc to p2p msg +struct NSPV_spentinfo komodo_NSPV_spentinfo(uint256 txid,int32_t vout) // just a primitive example of how to add new rpc to p2p msg { - std::vector request; struct nSPV_spentinfo I; int32_t i,numsent = 0; uint32_t timestamp = (uint32_t)time(NULL); + std::vector request; struct NSPV_spentinfo I; int32_t i,numsent = 0; uint32_t timestamp = (uint32_t)time(NULL); // lookup spentinfo for (i=0; iSetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); + if ( KOMODO_NSPV != 0 && (pfrom->nServices & NODE_NSPV) == 0 ) + { + fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); + pfrom->fDisconnect = true; + return false; + } // Mark this node as currently connected, so we update its timestamp later. if (pfrom->fNetworkNode) { LOCK(cs_main); From d984c6a7e0e3867777f7f8c3120c8e1e8cd6fca3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 09:42:14 -1100 Subject: [PATCH 053/659] pnode --- src/komodo_nSPV.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4fde5b5e0..59afa6ae0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -219,12 +219,12 @@ struct NSPV_spentinfo komodo_NSPV_spentinfo(uint256 txid,int32_t vout) // just a { if ( pnode->hSocket == INVALID_SOCKET ) continue; - if ( (pto->nServices & NODE_NSPV) != 0 && timestamp > pto->lastspent ) + if ( (pnode->nServices & NODE_NSPV) != 0 && timestamp > pto->lastspent ) { request.resize(1); request[0] = NSPV_SPENTINFO; - pto->lastspent = timestamp; - pto->PushMessage("getnSPV",request); + pnode->lastspent = timestamp; + pnode->PushMessage("getnSPV",request); if ( ++numsent >= 3 ) break; } From ad424236e584154c5397d7855e8e786bd9f3e605 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jul 2019 09:43:21 -1100 Subject: [PATCH 054/659] Again --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 59afa6ae0..6c46e049f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -219,7 +219,7 @@ struct NSPV_spentinfo komodo_NSPV_spentinfo(uint256 txid,int32_t vout) // just a { if ( pnode->hSocket == INVALID_SOCKET ) continue; - if ( (pnode->nServices & NODE_NSPV) != 0 && timestamp > pto->lastspent ) + if ( (pnode->nServices & NODE_NSPV) != 0 && timestamp > pnode->lastspent ) { request.resize(1); request[0] = NSPV_SPENTINFO; From 6f5566940a63ede617a77abcb767875803af5413 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 01:32:33 -1100 Subject: [PATCH 055/659] Serdes for NSPV structs and initial functionality --- src/komodo_defs.h | 3 + src/komodo_nSPV.h | 570 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 493 insertions(+), 80 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 784502dc8..5ea260db6 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -336,6 +336,9 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); int32_t komodo_currentheight(); +bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); +std::vector Mypubkey(); + struct NSPV_spentinfo { uint256 txid,spenttxid; diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 6c46e049f..e37a83746 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -18,6 +18,13 @@ * * ******************************************************************************/ +// todo: make sure no files are updated +// finalize structs, de/serialization +// rpc calls +// validate proofs + +// make sure to sanity check all vector lengths on receipt + #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H @@ -34,33 +41,15 @@ #define NSPV_SPENTINFO 0x0a #define NSPV_SPENTINFORESP 0x0b -struct NSPV_ntz +int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf) { - uint256 blockhash,txid,othertxid; - int32_t height,txidheight; -}; + if ( rwflag != 0 ) + memcpy(serialized,buf,len); + else memcpy(buf,serialized,len); + return(len) +} -struct NSPV_info -{ - struct NSPV_ntz notarization; - uint256 blockhash; - int32_t height; -}; - -struct NSPV_utxo -{ - uint256 txid; - int64_t satoshis,extradata; - int32_t vout,height,before,after; - std::vector tx,txproof; -}; - -struct NSPV_ntzs -{ - struct NSPV_ntz before,after; -}; - -struct NSPV_equiheader +struct NSPV_equihdr { int32_t nVersion; uint256 hashPrevBlock; @@ -68,106 +57,516 @@ struct NSPV_equiheader uint256 hashFinalSaplingRoot; uint32_t nTime; uint32_t nBits; - CPOSNonce nNonce; + uint256 nNonce; uint8_t nSolution[1344]; }; -struct NSPV_ntzproofhdr +int32_t NSPV_rwequihdr(int32_t rwflag,uint8_t *serialized,struct NSPV_equihdr *ptr) { - std::vector headers; - int32_t beforeheight,afterheight; + int32_t len = 0; + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nVersion),&ptr->nVersion); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->hashPrevBlock),(uint8_t *)&ptr->hashPrevBlock); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->hashMerkleRoot),(uint8_t *)&ptr->hashMerkleRoot); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->hashFinalSaplingRoot),(uint8_t *)&ptr->hashFinalSaplingRoot); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nTime),&ptr->nTime); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nBits),&ptr->nBits); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->nNonce),(uint8_t *)&ptr->nNonce); + len += iguana_rwbuf(rwflag,&serialized[len],sizeof(ptr->nSolution),ptr->nSolution); + return(len); +} + +int32_t iguana_rwequihdrvec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsizep,uint8_t struct NSPV_equihdr **ptrp) +{ + int32_t i,vsize,len = 0; + len += iguana_rwnum(rwflag,&serialized[len],sizeof(*vecsizep),vecsizep); + if ( (vsize= *vecsizep) != 0 ) + { + if ( *ptrp == 0 ) + *ptrp = calloc(sizeof(**ptrp),vsize); // relies on uint16_t being "small" to prevent mem exhaustion + for (i=0; i beforentz,afterntz; + int32_t len = 0; + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->satoshis),&ptr->satoshis); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->extradata),&ptr->extradata); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); + return(len); +} + +struct NSPV_utxosresp +{ + struct NSPV_utxoresp *utxos; + int64_t total,interest; + int32_t pad32; + uint16_t numutxos,pad16; }; -struct NSPV_MMRproof +int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,uint16_t *vecsizep,uint8_t struct NSPV_utxosresp **ptrp) // check mempool { - struct NSPV_ntzproofhdr hdr; - std::vector mmrproof; + int32_t i,vsize,len = 0; + len += iguana_rwnum(rwflag,&serialized[len],sizeof(*vecsizep),vecsizep); + if ( (vsize= *vecsizep) != 0 ) + { + if ( *ptrp == 0 ) + *ptrp = calloc(sizeof(**ptrp),vsize); // relies on uint16_t being "small" to prevent mem exhaustion + for (i=0; itotal),&ptr->total); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); + return(len); +} + +void NSPV_utxosresp_purge(struct NSPV_utxosresp *ptr) +{ + if ( ptr != 0 ) + { + if ( ptr->utxos != 0 ) + free(ptr->utxos); + memset(ptr,0,sizeof(*ptr)); + } +} + +struct NSPV_ntz +{ + uint256 blockhash,txid,othertxid; + int32_t height,txidheight; }; +int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) +{ + int32_t len = 0; + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->blockhash),(uint8_t *)&ptr->blockhash); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->othertxid),(uint8_t *)&ptr->othertxid); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->txidheight),&ptr->txidheight); + return(len); +} + +struct NSPV_ntzsresp +{ + struct NSPV_ntz prevntz,nextntz; +}; + +int32_t NSPV_rwntzsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsresp *ptr) +{ + int32_t len = 0; + len += NSPV_rwntz(rwflag,&serialized[len],sizeof(ptr->prevntz),&ptr->prevntz); + len += NSPV_rwntz(rwflag,&serialized[len],sizeof(ptr->nextntz),&ptr->nextntz); + return(len); +} + +void NSPV_ntzsresp_purge(struct NSPV_ntzsresp *ptr) +{ + if ( ptr != 0 ) + memset(ptr,0,sizeof(*ptr)); +} + +struct NSPV_inforesp +{ + struct NSPV_ntz notarization; + uint256 blockhash; + int32_t height,pad32; +}; + +int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp *ptr) +{ + int32_t len = 0; + len += NSPV_rwntz(rwflag,&serialized[len],sizeof(ptr->notarization),&ptr->notarization); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->blockhash),(uint8_t *)&ptr->blockhash); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + return(len); +} + +void NSPV_inforesp_purge(struct NSPV_inforesp *ptr) +{ + if ( ptr != 0 ) + memset(ptr,0,sizeof(*ptr)); +} + struct NSPV_txproof { uint256 txid; - std::vector tx,txproof; int32_t height; + uint16_t txlen,txprooflen; + uint8_t *tx,*txproof; }; -uint32_t NSPV_lastinfo,NSPV_lastutxos; -std::vector NSPV_utxos; -std::vector NSPV_spends; +int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *ptr) +{ + int32_t len = 0; + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); + len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); + len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); + return(len); +} + +void NSPV_txproof_purge(struct NSPV_txproof *ptr) +{ + if ( ptr != 0 ) + { + if ( ptr->tx != 0 ) + free(ptr->tx); + if ( ptr->txproof != 0 ) + free(ptr->txproof); + memset(ptr,0,sizeof(*ptr)); + } +} + +struct NSPV_utxo +{ + struct NSPV_txproof T; + int64_t satoshis,extradata; + int32_t vout,prevht,nextht,pad32; +}; + +int32_t NSPV_rwutxo(int32_t rwflag,uint8_t *serialized,struct NSPV_utxo *ptr) +{ + int32_t len = 0; + len += NSPV_rwtxproof(rwflag,&serialized[len],&ptr->T); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->satoshis),&ptr->satoshis); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->extradata),&ptr->extradata); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevht),&ptr->prevht); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nextht),&ptr->nextht); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + return(len); +} + +struct NSPV_ntzproofshared +{ + struct NSPV_equihdr *hdrs; + int32_t prevht,nextht,pad32; + uint16_t numhdrs,pad16; +}; + +int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzproofshared *ptr) +{ + int32_t len = 0; + len += iguana_rwequihdrvec(rwflag,&serialized[len],&ptr->numhdrs,&ptr->hdrs); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevht),&ptr->prevht); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nextht),&ptr->nextht); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); + return(len); +} + +struct NSPV_ntzsproofresp +{ + struct NSPV_ntzproofshared common; + uint32_t pad32; + uint16_t prevlen,nextlen; + uint8_t *prevntz,*nextntz; +}; + +int32_t NSPV_rwntzproof(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsproofresp *ptr) +{ + int32_t len = 0; + len += NSPV_rwntzproofshared(rwflag,&serialized[len],&ptr->common); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->prevlen,&ptr->prevntz); + len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->nextlen,&ptr->nextntz); + return(len); +} + +void NSPV_ntzsproofresp_purge(struct NSPV_ntzsproofresp *ptr) +{ + if ( ptr != 0 ) + { + if ( ptr->common.hdrs != 0 ) + free(ptr->common.hdrs); + if ( ptr->prevntz != 0 ) + free(ptr->prevntz); + if ( ptr->nextntz != 0 ) + free(ptr->nextntz); + memset(ptr,0,sizeof(*ptr)); + } +} + +struct NSPV_MMRproof +{ + struct NSPV_ntzproofhdr hdr; + // tbd +}; + +struct NSPV_spentinfo +{ + struct NSPV_txproof spent; + uint256 txid; + int32_t height,spentvini; +}; + +int32_t NSPV_rwspentinfo(int32_t rwflag,uint8_t *serialized,struct NSPV_spentinfo *ptr) // check mempool +{ + int32_t len = 0; + len += NSPV_rwtxproof(rwflag,&serialized[len],&ptr->spent); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->spentvini),&ptr->spentvini); + return(len); +} + +void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) +{ + if ( ptr != 0 ) + { + NSPV_txproof_purge(&ptr->spent); + memset(ptr,0,sizeof(*ptr)); + } +} // on fullnode: + +int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) +{ + int32_t prevMoMheight,len = 0; CBlockIndex *pindex; + if ( (pindex= chainActive.LastTip()) != 0 ) + { + ptr->height = pindex->GetHeight(); + ptr->blockhash = pindex->GetBlockHash(); + ptr->notarization.height = komodo_notarized_height(&prevMoMheight,&ptr->notarization.blockhash,&ptr->notarization.othertxid); + //ptr->notarization.txidheight = komodo_findnotarization(&ptr->notarization.txid,ptr->notarization.height,ptr->notarization.blockhash); + return(sizeof(*ptr)); + } else return(-1); +} + +int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check mempool +{ + int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,txheight,n = 0,len = 0; + std::vector > unspentOutputs; + fprintf(stderr,"getaddressutxos for %s\n",coinaddr); + SetCCunspents(unspentOutputs,coinaddr,false); + if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 ) + { + tipheight = chainActive.LastTip()->GetHeight(); + ptr->utxos = calloc(ptr->numutxos,sizeof(*ptr->utxos)); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + ptr->utxos[n].txid = it->first.txhash; + ptr->utxos[n].vout = (int32_t)it->first.index; + ptr->utxos[n].satoshis = it->second.satoshis; + ptr->utxos[n].height = it->second.blockHeight; + if ( ASSETCHAINS_SYMBOL[0] == 0 && it->second.satoshis >= 10*COIN ) + { + ptr->utxos[n].extradata = komodo_accrued_interest(&txheight,&locktime,ptr->utxos[n].txid,ptr->utxos[n].vout,ptr->utxos[n].height,ptr->utxos[n].satoshis,tipheight); + interest += ptr->utxos[n].extradata; + } + total += it->second.satoshis; + n++; + } + fprintf(stderr,"getaddressutxos for %s -> n.%d total %.8f interest %.8f\n",coinaddr,dstr(total),dstr(interest)); + if ( n == ptr->numutxos ) + { + ptr->total = total; + ptr->interest = interest; + return((int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos)); + } + } + if ( ptr->utxos != 0 ) + free(ptr->utxos); + memst(ptr,0,sizeof(*ptr)); + return(0); +} + +int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) +{ + int32_t len = 0; + return(sizeof(*ptr)); +} + +int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) +{ + int32_t len = 0; + return(len); +} + +int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) +{ + int32_t len = 0; + return(len); +} + +int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) +{ + int32_t len = 0; + return(len); +} + void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request { - int32_t len; std::vector response; uint32_t timestamp = (uint32_t)time(NULL); + int32_t len,slen; std::vector response; uint32_t timestamp; + timestamp = (uint32_t)time(NULL); if ( (len= request.size()) > 0 ) { - response.resize(1); - if ( len == 1 && request[0] == NSPV_INFO ) // info + if ( request[0] == NSPV_INFO ) // info { if ( timestamp > pfrom->lastinfo + ASSETCHAINS_BLOCKTIME/2 ) { - response[0] = NSPV_INFORESP; - pfrom->lastinfo = timestamp; - pfrom->PushMessage("nSPV",response); + struct NSPV_inforesp I; + memset(&I,0,sizeof(I)); + if ( (slen= NSPV_getinfo(&I)) > 0 ) + { + response.resize(1 + slen); + response[0] = NSPV_INFORESP; + NSPV_rwinforesp(1,&response[1],&I); + pfrom->PushMessage("nSPV",response); + pfrom->lastinfo = timestamp; + NSPV_inforesp_purge(&I); + } } } else if ( request[0] == NSPV_UTXOS ) { if ( timestamp > pfrom->lastutxos + ASSETCHAINS_BLOCKTIME/2 ) { - response[0] = NSPV_UTXOSRESP; - pfrom->lastutxos = timestamp; - // check mempool - pfrom->PushMessage("nSPV",response); + struct NSPV_utxosresp U; char coinaddr[64]; + if ( len < 64 && request[1] == len-2 ) + { + memcpy(coinaddr,&request[2],request[1]); + memset(&U,0,sizeof(U)); + slen = NSPV_getaddressutxos(&U,coinaddr); + response.resize(1 + slen); + response[0] = NSPV_UTXOSRESP; + if ( NSPV_rwutxosresp(1,&response[1],&U.numutxos,&U.utxos) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->lastutxos = timestamp; + } + NSPV_utxosresp_purge(&U); + } } } else if ( request[0] == NSPV_NTZS ) { if ( timestamp > pfrom->lastntzs ) { - response[0] = NSPV_NTZSRESP; - pfrom->lastntzs = timestamp; - pfrom->PushMessage("nSPV",response); + struct NSPV_ntzsresp N; int32_t height; + if ( len == 1+sizeof(height) ) + { + iguana_rwnum(rwflag,&request[1],sizeof(height),&height); + memset(&N,0,sizeof(N)); + slen = NSPV_getntzsresp(&N,height); + response.resize(1 + slen); + response[0] = NSPV_NTZSRESP; + if ( NSPV_rwntzsresp(1,&response[1],&N) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->lastntzs = timestamp; + } + NSPV_ntzsresp_purge(&N); + } } } else if ( request[0] == NSPV_NTZPROOF ) { if ( timestamp > pfrom->lastproof ) { - response[0] = NSPV_NTZPROOFRESP; - pfrom->lastproof = timestamp; - pfrom->PushMessage("nSPV",response); + struct NSPV_ntzsproofresp P; int32_t prevht,nextht; + if ( len == 1+sizeof(prevht)+sizeof(nextht) ) + { + iguana_rwnum(rwflag,&request[1],sizeof(prevht),&prevht); + iguana_rwnum(rwflag,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); + if ( prevht != 0 && nextht != 0 && nextht >= prevht ) + { + memset(&N,0,sizeof(N)); + slen = NSPV_getntzsproofresp(&P,prevht,nextht); + response.resize(1 + slen); + response[0] = NSPV_NTZPROOFRESP; + if ( NSPV_rwntzsresp(1,&response[1],&P) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->lastproof = timestamp; + } + NSPV_ntzsproofresp_purge(&P); + } + } } } else if ( request[0] == NSPV_TXPROOF ) { if ( timestamp > pfrom->lastproof ) { - response[0] = NSPV_TXPROOFRESP; - pfrom->lastproof = timestamp; - pfrom->PushMessage("nSPV",response); + struct NSPV_spentinfo P; uint256 txid; int32_t height; + if ( len == 1+sizeof(txid)+sizeof(height) ) + { + iguana_rwnum(rwflag,&request[1],sizeof(height),&height); + iguana_rwbignum(rwflag,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); + memset(&P,0,sizeof(P)); + slen = NSPV_gettxproof(&P,txid,height); + response.resize(1 + slen); + response[0] = NSPV_TXPROOFRESP; + if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->lastproof = timestamp; + } + NSPV_txproof_purge(&P); + } } } else if ( request[0] == NSPV_SPENTINFO ) { if ( timestamp > pfrom->lastspent ) { - response[0] = NSPV_SPENTINFORESP; - // check mempool - pfrom->lastspent = timestamp; - pfrom->PushMessage("nSPV",response); + struct NSPV_spentinfo S; int32_t vout; uint256 txid; + if ( len == 1+sizeof(txid)+sizeof(vout) ) + { + iguana_rwnum(rwflag,&request[1],sizeof(vout),&vout); + iguana_rwbignum(rwflag,&request[1+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); + memset(&S,0,sizeof(S)); + slen = NSPV_getspentinfo(&S,txid,vout); + response.resize(1 + slen); + response[0] = NSPV_SPENTINFORESP; + if ( NSPV_rwspentinfo(1,&response[1],&S) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->lastspent = timestamp; + } + NSPV_spentinfo_purge(&S); + } } } } } // on nSPV client +uint32_t NSPV_lastinfo,NSPV_lastutxos; +int32_t NSPV_numutxos,NSPV_numspends; +struct NSPV_utxo *NSPV_utxos; +struct NSPV_spentinfo *NSPV_spends; + void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response { int32_t len; uint32_t timestamp = (uint32_t)time(NULL); @@ -176,22 +575,22 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r switch ( response[0] ) { case NSPV_INFORESP: - fprintf(stderr,"got info response %u\n",timestamp); // update current height and ntrz status + fprintf(stderr,"got info response %u size.%d\n",timestamp,(int32_t)response.size()); // update current height and ntrz status break; case NSPV_UTXOSRESP: - fprintf(stderr,"got utxos response %u\n",timestamp); // update utxos list + fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos list break; case NSPV_NTZSRESP: - fprintf(stderr,"got ntzs response %u\n",timestamp); // update utxos[i] + fprintf(stderr,"got ntzs response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; case NSPV_NTZPROOFRESP: - fprintf(stderr,"got ntzproof response %u\n",timestamp); // update utxos[i] + fprintf(stderr,"got ntzproof response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; case NSPV_TXPROOFRESP: - fprintf(stderr,"got txproof response %u\n",timestamp); // update utxos[i] + fprintf(stderr,"got txproof response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; case NSPV_SPENTINFORESP: - fprintf(stderr,"got spentinfo response %u\n",timestamp); // update utxos[i] + fprintf(stderr,"got spentinfo response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); break; @@ -201,14 +600,17 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r void komodo_NSPV_spentinfoclear() { - NSPV_spends.resize(0); + if ( NSPV_spends != 0 ) + free(NSPV_spends); + NSPV_spends = 0; + NSPV_numspends = 0; } struct NSPV_spentinfo komodo_NSPV_spentinfo(uint256 txid,int32_t vout) // just a primitive example of how to add new rpc to p2p msg { - std::vector request; struct NSPV_spentinfo I; int32_t i,numsent = 0; uint32_t timestamp = (uint32_t)time(NULL); - // lookup spentinfo - for (i=0; i request; struct NSPV_spentinfo I; int32_t i,numsent = 0; uint32_t timestamp; + timestamp = (uint32_t)time(NULL); + for (i=0; ihSocket == INVALID_SOCKET ) continue; - if ( (pnode->nServices & NODE_NSPV) != 0 && timestamp > pnode->lastspent ) + if ( (pnode->nServices & NODE_SPENTINDEX) != 0 && timestamp > pnode->lastspent ) { request.resize(1); request[0] = NSPV_SPENTINFO; @@ -238,12 +640,12 @@ void komodo_nSPV(CNode *pto) return; if ( timestamp > pto->lastntzs || timestamp > pto->lastproof ) { - for (i=0; i pto->lastntzs ) + if ( NSPV_utxos[i].prevlen == 0 && timestamp > pto->lastntzs ) { request[0] = NSPV_NTZS; pto->lastntzs = timestamp; @@ -276,10 +678,18 @@ void komodo_nSPV(CNode *pto) // get utxo since lastheight if ( (rand() % 100) < 10 ) { - request.resize(1); - request[0] = NSPV_UTXOS; - NSPV_lastutxos = pto->lastutxos = timestamp; - pto->PushMessage("getnSPV",request); + char coinaddr[64]; int32_t slen; + Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG); + slen = (int32_t)strlen(coinaddr); + if ( slen < 64 ) + { + request.resize(1 + 1 + slen); + request[0] = NSPV_UTXOS; + request[1] = slen; + memcpy(&request[2],coinaddr,slen); + NSPV_lastutxos = pto->lastutxos = timestamp; + pto->PushMessage("getnSPV",request); + } } } } From 3bf8b8862ff93fd82e87cd80eac067ce105c901f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 01:54:35 -1100 Subject: [PATCH 056/659] Syntax --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e37a83746..98048e1fb 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -46,7 +46,7 @@ int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *bu if ( rwflag != 0 ) memcpy(serialized,buf,len); else memcpy(buf,serialized,len); - return(len) + return(len); } struct NSPV_equihdr @@ -75,7 +75,7 @@ int32_t NSPV_rwequihdr(int32_t rwflag,uint8_t *serialized,struct NSPV_equihdr *p return(len); } -int32_t iguana_rwequihdrvec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsizep,uint8_t struct NSPV_equihdr **ptrp) +int32_t iguana_rwequihdrvec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsizep,struct NSPV_equihdr **ptrp) { int32_t i,vsize,len = 0; len += iguana_rwnum(rwflag,&serialized[len],sizeof(*vecsizep),vecsizep); From 665a272e72b0c2b326a0fa06882fea363fc22bee Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 02:02:05 -1100 Subject: [PATCH 057/659] Syntax --- src/komodo_nSPV.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 98048e1fb..668482560 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -82,7 +82,7 @@ int32_t iguana_rwequihdrvec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsize if ( (vsize= *vecsizep) != 0 ) { if ( *ptrp == 0 ) - *ptrp = calloc(sizeof(**ptrp),vsize); // relies on uint16_t being "small" to prevent mem exhaustion + *ptrp = (struct NSPV_equihdr *)calloc(sizeof(**ptrp),vsize); // relies on uint16_t being "small" to prevent mem exhaustion for (i=0; inumutxos= (int32_t)unspentOutputs.size()) > 0 ) { tipheight = chainActive.LastTip()->GetHeight(); - ptr->utxos = calloc(ptr->numutxos,sizeof(*ptr->utxos)); + ptr->utxos = (struct NSPV_utxoresp *)calloc(ptr->numutxos,sizeof(*ptr->utxos)); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { ptr->utxos[n].txid = it->first.txhash; From 456d4a9bfb0bca6d907d45dc332c301a2c2306da Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 02:07:03 -1100 Subject: [PATCH 058/659] Fix utxos --- src/komodo_nSPV.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 668482560..ec853c682 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -128,16 +128,16 @@ struct NSPV_utxosresp uint16_t numutxos,pad16; }; -int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,uint16_t *vecsizep,struct NSPV_utxosresp **ptrp) // check mempool +int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosresp *ptr) // check mempool { - int32_t i,vsize,len = 0; - len += iguana_rwnum(rwflag,&serialized[len],sizeof(*vecsizep),vecsizep); - if ( (vsize= *vecsizep) != 0 ) + int32_t i,len = 0; + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->numutxos),&ptr->numutxos); + if ( ptr->numutxos != 0 ) { - if ( *ptrp == 0 ) - *ptrp = (struct NSPV_utxosresp *)calloc(sizeof(**ptrp),vsize); // relies on uint16_t being "small" to prevent mem exhaustion - for (i=0; iutxos == 0 ) + ptr->utxos = (struct NSPV_utxoresp *)calloc(sizeof(*ptr->utxos),ptr->numutxos); // relies on uint16_t being "small" to prevent mem exhaustion + for (i=0; inumutxos; i++) + len += NSPV_rwutxoresp(rwflag,&serialized[len],&ptr->utxos[i]); } len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->total),&ptr->total); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); @@ -459,7 +459,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req slen = NSPV_getaddressutxos(&U,coinaddr); response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; - if ( NSPV_rwutxosresp(1,&response[1],&U.numutxos,&U.utxos) == slen ) + if ( NSPV_rwutxosresp(1,&response[1],&U.utxos) == slen ) { pfrom->PushMessage("nSPV",response); pfrom->lastutxos = timestamp; From 836ffe9ad4a0a7bbcd8dc29340b277536a057e23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 02:12:34 -1100 Subject: [PATCH 059/659] Syntax --- src/komodo_nSPV.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index ec853c682..0085d356e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -181,8 +181,8 @@ struct NSPV_ntzsresp int32_t NSPV_rwntzsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsresp *ptr) { int32_t len = 0; - len += NSPV_rwntz(rwflag,&serialized[len],sizeof(ptr->prevntz),&ptr->prevntz); - len += NSPV_rwntz(rwflag,&serialized[len],sizeof(ptr->nextntz),&ptr->nextntz); + len += NSPV_rwntz(rwflag,&serialized[len],&ptr->prevntz); + len += NSPV_rwntz(rwflag,&serialized[len],&ptr->nextntz); return(len); } @@ -202,7 +202,7 @@ struct NSPV_inforesp int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp *ptr) { int32_t len = 0; - len += NSPV_rwntz(rwflag,&serialized[len],sizeof(ptr->notarization),&ptr->notarization); + len += NSPV_rwntz(rwflag,&serialized[len],&ptr->notarization); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->blockhash),(uint8_t *)&ptr->blockhash); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); @@ -317,7 +317,7 @@ void NSPV_ntzsproofresp_purge(struct NSPV_ntzsproofresp *ptr) struct NSPV_MMRproof { - struct NSPV_ntzproofhdr hdr; + struct NSPV_ntzproofshared common; // tbd }; From 2ad7732c8a87da5d89aa0126610c0311e5928297 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 02:14:58 -1100 Subject: [PATCH 060/659] Fix spent info --- src/komodo_defs.h | 5 +++-- src/komodo_nSPV.h | 7 ------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 5ea260db6..b36af620d 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -341,8 +341,9 @@ std::vector Mypubkey(); struct NSPV_spentinfo { - uint256 txid,spenttxid; - int32_t vout,height,spentvin,spentheight; + struct NSPV_txproof spent; + uint256 txid; + int32_t height,spentvini; }; void komodo_NSPV_spentinfoclear(); struct NSPV_spentinfo komodo_NSPV_spentinfo(uint256 txid,int32_t vout); diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 0085d356e..9235916e1 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -321,13 +321,6 @@ struct NSPV_MMRproof // tbd }; -struct NSPV_spentinfo -{ - struct NSPV_txproof spent; - uint256 txid; - int32_t height,spentvini; -}; - int32_t NSPV_rwspentinfo(int32_t rwflag,uint8_t *serialized,struct NSPV_spentinfo *ptr) // check mempool { int32_t len = 0; From 87d2264b2ad40fb07a271a8310020823f24d7c91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 02:16:25 -1100 Subject: [PATCH 061/659] Syntax --- src/komodo_defs.h | 8 -------- src/komodo_nSPV.h | 7 +++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index b36af620d..0a628b216 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -339,14 +339,6 @@ int32_t komodo_currentheight(); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); std::vector Mypubkey(); -struct NSPV_spentinfo -{ - struct NSPV_txproof spent; - uint256 txid; - int32_t height,spentvini; -}; -void komodo_NSPV_spentinfoclear(); -struct NSPV_spentinfo komodo_NSPV_spentinfo(uint256 txid,int32_t vout); #endif diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9235916e1..0085d356e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -321,6 +321,13 @@ struct NSPV_MMRproof // tbd }; +struct NSPV_spentinfo +{ + struct NSPV_txproof spent; + uint256 txid; + int32_t height,spentvini; +}; + int32_t NSPV_rwspentinfo(int32_t rwflag,uint8_t *serialized,struct NSPV_spentinfo *ptr) // check mempool { int32_t len = 0; From f5be07ddfe4d528f157b109988e9f85fde1ca2e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 02:26:24 -1100 Subject: [PATCH 062/659] Syntax --- src/komodo_nSPV.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 0085d356e..85ce08ba9 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -386,7 +386,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check total += it->second.satoshis; n++; } - fprintf(stderr,"getaddressutxos for %s -> n.%d total %.8f interest %.8f\n",coinaddr,dstr(total),dstr(interest)); + fprintf(stderr,"getaddressutxos for %s -> n.%d total %.8f interest %.8f\n",coinaddr,n,dstr(total),dstr(interest)); if ( n == ptr->numutxos ) { ptr->total = total; @@ -396,7 +396,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check } if ( ptr->utxos != 0 ) free(ptr->utxos); - memst(ptr,0,sizeof(*ptr)); + memset(ptr,0,sizeof(*ptr)); return(0); } @@ -432,7 +432,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { if ( request[0] == NSPV_INFO ) // info { - if ( timestamp > pfrom->lastinfo + ASSETCHAINS_BLOCKTIME/2 ) + if ( len == 1 && timestamp > pfrom->lastinfo + ASSETCHAINS_BLOCKTIME/2 ) { struct NSPV_inforesp I; memset(&I,0,sizeof(I)); @@ -459,7 +459,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req slen = NSPV_getaddressutxos(&U,coinaddr); response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; - if ( NSPV_rwutxosresp(1,&response[1],&U.utxos) == slen ) + if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) { pfrom->PushMessage("nSPV",response); pfrom->lastutxos = timestamp; @@ -475,7 +475,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req struct NSPV_ntzsresp N; int32_t height; if ( len == 1+sizeof(height) ) { - iguana_rwnum(rwflag,&request[1],sizeof(height),&height); + iguana_rwnum(0,&request[1],sizeof(height),&height); memset(&N,0,sizeof(N)); slen = NSPV_getntzsresp(&N,height); response.resize(1 + slen); @@ -496,11 +496,11 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req struct NSPV_ntzsproofresp P; int32_t prevht,nextht; if ( len == 1+sizeof(prevht)+sizeof(nextht) ) { - iguana_rwnum(rwflag,&request[1],sizeof(prevht),&prevht); - iguana_rwnum(rwflag,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); + iguana_rwnum(0,&request[1],sizeof(prevht),&prevht); + iguana_rwnum(0,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); if ( prevht != 0 && nextht != 0 && nextht >= prevht ) { - memset(&N,0,sizeof(N)); + memset(&P,0,sizeof(P)); slen = NSPV_getntzsproofresp(&P,prevht,nextht); response.resize(1 + slen); response[0] = NSPV_NTZPROOFRESP; @@ -518,11 +518,11 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { if ( timestamp > pfrom->lastproof ) { - struct NSPV_spentinfo P; uint256 txid; int32_t height; + struct NSPV_txproof P; uint256 txid; int32_t height; if ( len == 1+sizeof(txid)+sizeof(height) ) { - iguana_rwnum(rwflag,&request[1],sizeof(height),&height); - iguana_rwbignum(rwflag,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); + iguana_rwnum(0,&request[1],sizeof(height),&height); + iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); memset(&P,0,sizeof(P)); slen = NSPV_gettxproof(&P,txid,height); response.resize(1 + slen); @@ -543,8 +543,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req struct NSPV_spentinfo S; int32_t vout; uint256 txid; if ( len == 1+sizeof(txid)+sizeof(vout) ) { - iguana_rwnum(rwflag,&request[1],sizeof(vout),&vout); - iguana_rwbignum(rwflag,&request[1+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); + iguana_rwnum(0,&request[1],sizeof(vout),&vout); + iguana_rwbignum(0,&request[1+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); memset(&S,0,sizeof(S)); slen = NSPV_getspentinfo(&S,txid,vout); response.resize(1 + slen); From 1a45fa08da083f72321fdf26fca7d269d72a9fdf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 02:33:05 -1100 Subject: [PATCH 063/659] Syntax --- src/komodo_nSPV.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 85ce08ba9..c2d8a6254 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -325,7 +325,7 @@ struct NSPV_spentinfo { struct NSPV_txproof spent; uint256 txid; - int32_t height,spentvini; + int32_t vout,height,spentvini; }; int32_t NSPV_rwspentinfo(int32_t rwflag,uint8_t *serialized,struct NSPV_spentinfo *ptr) // check mempool @@ -333,6 +333,7 @@ int32_t NSPV_rwspentinfo(int32_t rwflag,uint8_t *serialized,struct NSPV_spentinf int32_t len = 0; len += NSPV_rwtxproof(rwflag,&serialized[len],&ptr->spent); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->spentvini),&ptr->spentvini); return(len); @@ -504,7 +505,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req slen = NSPV_getntzsproofresp(&P,prevht,nextht); response.resize(1 + slen); response[0] = NSPV_NTZPROOFRESP; - if ( NSPV_rwntzsresp(1,&response[1],&P) == slen ) + if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) { pfrom->PushMessage("nSPV",response); pfrom->lastproof = timestamp; @@ -623,12 +624,15 @@ struct NSPV_spentinfo komodo_NSPV_spentinfo(uint256 txid,int32_t vout) // just a continue; if ( (pnode->nServices & NODE_SPENTINDEX) != 0 && timestamp > pnode->lastspent ) { - request.resize(1); - request[0] = NSPV_SPENTINFO; - pnode->lastspent = timestamp; - pnode->PushMessage("getnSPV",request); - if ( ++numsent >= 3 ) - break; + if ( 0 ) // submit actual request + { + request.resize(1); + request[0] = NSPV_SPENTINFO; + pnode->lastspent = timestamp; + pnode->PushMessage("getnSPV",request); + if ( ++numsent >= 3 ) + break; + } } } } @@ -642,7 +646,7 @@ void komodo_nSPV(CNode *pto) { for (i=0; i pto->lastntzs ) From 0bc442146d754f8b203a6598197755ad3974b8ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 02:44:13 -1100 Subject: [PATCH 064/659] Syntax --- src/komodo_nSPV.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c2d8a6254..b7ad13931 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -291,7 +291,7 @@ struct NSPV_ntzsproofresp uint8_t *prevntz,*nextntz; }; -int32_t NSPV_rwntzproof(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsproofresp *ptr) +int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsproofresp *ptr) { int32_t len = 0; len += NSPV_rwntzproofshared(rwflag,&serialized[len],&ptr->common); @@ -646,10 +646,10 @@ void komodo_nSPV(CNode *pto) { for (i=0; i pto->lastntzs ) + if ( NSPV_utxos[i].prevht == 0 && timestamp > pto->lastntzs ) { request[0] = NSPV_NTZS; pto->lastntzs = timestamp; @@ -658,7 +658,7 @@ void komodo_nSPV(CNode *pto) } else if ( timestamp > pto->lastproof ) { - if ( NSPV_utxos[i].tx.size() == 0 ) + if ( NSPV_utxos[i].T.txlen == 0 ) { request[0] = NSPV_TXPROOF; pto->lastproof = timestamp; From ab0166b9974876b86da48fdc10fe8069557ba147 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 02:49:43 -1100 Subject: [PATCH 065/659] -defs --- src/komodo_defs.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 0a628b216..6106a6000 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -336,9 +336,5 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); int32_t komodo_currentheight(); -bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); -std::vector Mypubkey(); - - #endif From 6e0ce513e6dd28d41a20756073e4971fc1e19e20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 03:01:36 -1100 Subject: [PATCH 066/659] Test --- src/komodo_nSPV.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b7ad13931..117438e51 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -124,7 +124,7 @@ struct NSPV_utxosresp { struct NSPV_utxoresp *utxos; int64_t total,interest; - int32_t pad32; + int32_t nodeheight; uint16_t numutxos,pad16; }; @@ -141,7 +141,7 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres } len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->total),&ptr->total); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); return(len); } @@ -372,6 +372,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 ) { tipheight = chainActive.LastTip()->GetHeight(); + ptr->nodeheight = tipheight; ptr->utxos = (struct NSPV_utxoresp *)calloc(ptr->numutxos,sizeof(*ptr->utxos)); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { From 1713a171cd5db7097685d67ce76a4bf69d1cc07a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 03:09:33 -1100 Subject: [PATCH 067/659] Adjust Len by sizeof ptr --- src/komodo_nSPV.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 117438e51..bd5b5cbef 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -388,12 +388,13 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check total += it->second.satoshis; n++; } - fprintf(stderr,"getaddressutxos for %s -> n.%d total %.8f interest %.8f\n",coinaddr,n,dstr(total),dstr(interest)); + len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos - sizeof(ptr->utxos)); + fprintf(stderr,"getaddressutxos for %s -> n.%d:%d total %.8f interest %.8f len.%d\n",coinaddr,n,ptr->numutxos,dstr(total),dstr(interest),len); if ( n == ptr->numutxos ) { ptr->total = total; ptr->interest = interest; - return((int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos)); + return(len); } } if ( ptr->utxos != 0 ) @@ -461,6 +462,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req slen = NSPV_getaddressutxos(&U,coinaddr); response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; + printf("slen.%d\n",slen); if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) { pfrom->PushMessage("nSPV",response); From feef1e6512477d848b8547ccf283530ca104430f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 03:20:09 -1100 Subject: [PATCH 068/659] Null term coinaddr --- src/komodo_nSPV.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index bd5b5cbef..06a251ca3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -452,12 +452,14 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } else if ( request[0] == NSPV_UTXOS ) { - if ( timestamp > pfrom->lastutxos + ASSETCHAINS_BLOCKTIME/2 ) + //if ( timestamp > pfrom->lastutxos + ASSETCHAINS_BLOCKTIME/2 ) { struct NSPV_utxosresp U; char coinaddr[64]; + printf("len.%d request[1] %d\n",len,request[1]); if ( len < 64 && request[1] == len-2 ) { memcpy(coinaddr,&request[2],request[1]); + coinaddr[request[1]] = 0; memset(&U,0,sizeof(U)); slen = NSPV_getaddressutxos(&U,coinaddr); response.resize(1 + slen); From 8d7a34bae0472cf22062ab63d725656f8ae256a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 04:51:08 -1100 Subject: [PATCH 069/659] txproof and spent info --- src/komodo_nSPV.h | 101 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 77 insertions(+), 24 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 06a251ca3..529e8adb6 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -325,7 +325,7 @@ struct NSPV_spentinfo { struct NSPV_txproof spent; uint256 txid; - int32_t vout,height,spentvini; + int32_t vout,spentvini; }; int32_t NSPV_rwspentinfo(int32_t rwflag,uint8_t *serialized,struct NSPV_spentinfo *ptr) // check mempool @@ -334,7 +334,6 @@ int32_t NSPV_rwspentinfo(int32_t rwflag,uint8_t *serialized,struct NSPV_spentinf len += NSPV_rwtxproof(rwflag,&serialized[len],&ptr->spent); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->spentvini),&ptr->spentvini); return(len); } @@ -365,11 +364,13 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check mempool { - int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,txheight,n = 0,len = 0; + int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; std::vector > unspentOutputs; fprintf(stderr,"getaddressutxos for %s\n",coinaddr); SetCCunspents(unspentOutputs,coinaddr,false); - if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 ) + maxlen = MAX_BLOCK_SIZE(tipheight) - 512; + maxlen /= sizeof(*ptr->utxos); + if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); ptr->nodeheight = tipheight; @@ -388,13 +389,16 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check total += it->second.satoshis; n++; } - len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos - sizeof(ptr->utxos)); - fprintf(stderr,"getaddressutxos for %s -> n.%d:%d total %.8f interest %.8f len.%d\n",coinaddr,n,ptr->numutxos,dstr(total),dstr(interest),len); - if ( n == ptr->numutxos ) + if ( len < maxlen ) { - ptr->total = total; - ptr->interest = interest; - return(len); + len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos - sizeof(ptr->utxos)); + fprintf(stderr,"getaddressutxos for %s -> n.%d:%d total %.8f interest %.8f len.%d\n",coinaddr,n,ptr->numutxos,dstr(total),dstr(interest),len); + if ( n == ptr->numutxos ) + { + ptr->total = total; + ptr->interest = interest; + return(len); + } } } if ( ptr->utxos != 0 ) @@ -409,13 +413,46 @@ int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) return(sizeof(*ptr)); } -int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) +int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) { - int32_t len = 0; - return(len); + int32_t flag = 0,len = 0; CTransaction tx; uint256 hashBlock; CBlock block; CBlockIndex *pindex; + { + LOCK(cs_main); + if (!GetTransaction(txid, tx, hashBlock, false)) + return(-1); + string strHex = EncodeHexTx(tx); + ptr->txlen = (int32_t)strHex.size() >> 1; + ptr->tx = (uint8_t *)calloc(1,ptr->txlen); + decode_hex(ptr->tx,ptr->txlen,strHex.c_str()); + ptr->txid = txid; + ptr->height = height; + if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) + { + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + if ( tx.GetHash() == txid ) + { + flag = 1; + break; + } + } + if ( flag != 0 ) + { + CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); + CMerkleBlock mb(block, setTxids); + ssMB << mb; + std::vector proof(ssMB.begin(), ssMB.end()); + ptr->txprooflen = (int32_t)proof.size(); + ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); + memcpy(ptr->txproof,&proof[0],ptr->txprooflen); + return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); + } + } + } + return(-1); } -int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) +int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) { int32_t len = 0; return(len); @@ -424,6 +461,20 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) { int32_t len = 0; + ptr->txid = txid; + ptr->vout = vout; + ptr->spentvini = -1; + len = (int32_t)(sizeof(*ptr) - sizeof(ptr->spent.tx) - sizeof(ptr->spent.txproof)); + if ( CCgetspenttxid(ptr->spent.txid,ptr->spentvini,ptr->spent.height,txid,vout) == 0 ) + { + if ( NSPV_gettxproof(&ptr->spent,ptr->spent.txid,ptr->spent.height) > 0 ) + len += ptr->spent.txlen + ptr->spent.txprooflen; + else + { + NSPV_txproof_purge(&ptr->spent); + return(-1); + } + } return(len); } @@ -452,10 +503,9 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } else if ( request[0] == NSPV_UTXOS ) { - //if ( timestamp > pfrom->lastutxos + ASSETCHAINS_BLOCKTIME/2 ) + if ( timestamp > pfrom->lastutxos + ASSETCHAINS_BLOCKTIME/2 ) { struct NSPV_utxosresp U; char coinaddr[64]; - printf("len.%d request[1] %d\n",len,request[1]); if ( len < 64 && request[1] == len-2 ) { memcpy(coinaddr,&request[2],request[1]); @@ -464,7 +514,6 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req slen = NSPV_getaddressutxos(&U,coinaddr); response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; - printf("slen.%d\n",slen); if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) { pfrom->PushMessage("nSPV",response); @@ -552,15 +601,17 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwnum(0,&request[1],sizeof(vout),&vout); iguana_rwbignum(0,&request[1+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); memset(&S,0,sizeof(S)); - slen = NSPV_getspentinfo(&S,txid,vout); - response.resize(1 + slen); - response[0] = NSPV_SPENTINFORESP; - if ( NSPV_rwspentinfo(1,&response[1],&S) == slen ) + if ( (slen= NSPV_getspentinfo(&S,txid,vout)) > 0 ) { - pfrom->PushMessage("nSPV",response); - pfrom->lastspent = timestamp; + response.resize(1 + slen); + response[0] = NSPV_SPENTINFORESP; + if ( NSPV_rwspentinfo(1,&response[1],&S) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->lastspent = timestamp; + } + NSPV_spentinfo_purge(&S); } - NSPV_spentinfo_purge(&S); } } } @@ -581,9 +632,11 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r switch ( response[0] ) { case NSPV_INFORESP: + // deser and display fprintf(stderr,"got info response %u size.%d\n",timestamp,(int32_t)response.size()); // update current height and ntrz status break; case NSPV_UTXOSRESP: + // deser and process fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos list break; case NSPV_NTZSRESP: From 64a690a5f602986be06d0a13d59e03be98c7210e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 04:56:58 -1100 Subject: [PATCH 070/659] Syntax --- src/komodo_nSPV.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 529e8adb6..dbe7c7775 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -423,7 +423,7 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) string strHex = EncodeHexTx(tx); ptr->txlen = (int32_t)strHex.size() >> 1; ptr->tx = (uint8_t *)calloc(1,ptr->txlen); - decode_hex(ptr->tx,ptr->txlen,strHex.c_str()); + decode_hex(ptr->tx,ptr->txlen,(char *)strHex.c_str()); ptr->txid = txid; ptr->height = height; if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) @@ -438,10 +438,12 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) } if ( flag != 0 ) { + set setTxids; CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); + setTxids.insert(txid); CMerkleBlock mb(block, setTxids); ssMB << mb; - std::vector proof(ssMB.begin(), ssMB.end()); + std::vector proof(ssMB.begin(), ssMB.end()); ptr->txprooflen = (int32_t)proof.size(); ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); memcpy(ptr->txproof,&proof[0],ptr->txprooflen); From d6833b0361c2d366f838eab923b574fee4f8f62a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 06:17:43 -1100 Subject: [PATCH 071/659] Finish all but one full node side functions --- src/komodo_defs.h | 1 + src/komodo_nSPV.h | 183 ++++++++++++++++++++++++++++++++------------ src/komodo_notary.h | 24 ++++++ 3 files changed, 158 insertions(+), 50 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 6106a6000..cef5c4d1c 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -335,6 +335,7 @@ int64_t komodo_pricemult(int32_t ind); int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); int32_t komodo_currentheight(); +int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height); #endif diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index dbe7c7775..f5e3cb7d9 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1,7 +1,3 @@ -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2014 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * @@ -18,12 +14,11 @@ * * ******************************************************************************/ -// todo: make sure no files are updated -// finalize structs, de/serialization -// rpc calls +// todo: +// make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) // validate proofs - // make sure to sanity check all vector lengths on receipt +// determine if it makes sense to be scanning mempool for the utxo/spentinfo requests #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H @@ -286,7 +281,8 @@ int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz struct NSPV_ntzsproofresp { struct NSPV_ntzproofshared common; - uint32_t pad32; + uint256 prevtxid,nexttxid; + uint32_t pad32,prevtxidht,nexttxidht; uint16_t prevlen,nextlen; uint8_t *prevntz,*nextntz; }; @@ -295,7 +291,11 @@ int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzs { int32_t len = 0; len += NSPV_rwntzproofshared(rwflag,&serialized[len],&ptr->common); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->prevtxid),(uint8_t *)&ptr->prevtxid); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->nexttxid),(uint8_t *)&ptr->nexttxid); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevtxidht),&ptr->prevtxidht); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nexttxidht),&ptr->nexttxidht); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->prevlen,&ptr->prevntz); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->nextlen,&ptr->nextntz); return(len); @@ -348,6 +348,16 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) } // on fullnode: +// NSPV_get... functions need to return the exact serialized length, which is the size of the structure minus size of pointers, plus size of allocated data + +uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) +{ + uint256 ntztxid; + *ntzheightp = height + 2; // random value; + // find notarization for height, return its txid and set *ntzheightp + fprintf(stderr,"implement NSPV_getnotarization_txid\n"); + return(ntztxid); +} int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) { @@ -357,7 +367,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) ptr->height = pindex->GetHeight(); ptr->blockhash = pindex->GetBlockHash(); ptr->notarization.height = komodo_notarized_height(&prevMoMheight,&ptr->notarization.blockhash,&ptr->notarization.othertxid); - //ptr->notarization.txidheight = komodo_findnotarization(&ptr->notarization.txid,ptr->notarization.height,ptr->notarization.blockhash); + ptr->notarization.txid = NSPV_getnotarization_txid(&ptr->notarization.txidheight,ptr->notarization.height); return(sizeof(*ptr)); } else return(-1); } @@ -407,57 +417,128 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check return(0); } +int32_t NSPV_npextract(struct NSPV_ntz *ptr,struct notarized_checkpoint *np) +{ + int32_t ntzheight; + ptr->blockhash = np->notarized_hash; + ptr->height = np->notarized_height; + ptr->txidheight = np->nHeight; + ptr->othertxid = np->notarized_desttxid; + ptr->txid = NSPV_getnotarization_txid(&ntzheight,ptr->height); + if ( ntzheight != ptr->txidheight ) + { + fprintf(stderr,"NSPV_npextract ntzheight.%d != ptr->txidheight.%d\n",ntzheight,ptr->txidheight); + return(-1); + } else return(0); +} + int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) { - int32_t len = 0; + struct notarized_checkpoint *nps[2]; + if ( komodo_notarized_bracket(nps,height) == 0 ) + { + if ( nps[0] != 0 ) + { + if ( NSPV_npextract(&ptr->prevntz,nps[0]) < 0 ) + return(-1); + } + if ( nps[1] != 0 ) + { + if ( NSPV_npextract(&ptr->nextntz,nps[1]) < 0 ) + return(-1); + } + } return(sizeof(*ptr)); } +uint8_t *NSPV_getrawtx(uint256 &hashBlock,int32_t *txlenp,uint256 txid) +{ + CTransaction tx; uint8_t *rawtx = 0; + *txlenp = 0; + { + LOCK(cs_main); + if (!GetTransaction(txid, tx, hashBlock, false)) + return(0); + string strHex = EncodeHexTx(tx); + *txlenp = (int32_t)strHex.size() >> 1; + rawtx = (uint8_t *)calloc(1,*txlenp); + decode_hex(rawtx,*txlenp,(char *)strHex.c_str()); + } + return(rawtx); +} + int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) { - int32_t flag = 0,len = 0; CTransaction tx; uint256 hashBlock; CBlock block; CBlockIndex *pindex; + int32_t flag = 0,len = 0; uint256 hashBlock; CBlock block; CBlockIndex *pindex; + if ( (ptr->tx= NSPV_getrawtx(hashBlock,&ptr->txlen,txid)) == 0 ) + return(-1); + ptr->txid = txid; + ptr->height = height; + if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) { - LOCK(cs_main); - if (!GetTransaction(txid, tx, hashBlock, false)) - return(-1); - string strHex = EncodeHexTx(tx); - ptr->txlen = (int32_t)strHex.size() >> 1; - ptr->tx = (uint8_t *)calloc(1,ptr->txlen); - decode_hex(ptr->tx,ptr->txlen,(char *)strHex.c_str()); - ptr->txid = txid; - ptr->height = height; - if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) + BOOST_FOREACH(const CTransaction&tx, block.vtx) { - BOOST_FOREACH(const CTransaction&tx, block.vtx) + if ( tx.GetHash() == txid ) { - if ( tx.GetHash() == txid ) - { - flag = 1; - break; - } - } - if ( flag != 0 ) - { - set setTxids; - CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); - setTxids.insert(txid); - CMerkleBlock mb(block, setTxids); - ssMB << mb; - std::vector proof(ssMB.begin(), ssMB.end()); - ptr->txprooflen = (int32_t)proof.size(); - ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); - memcpy(ptr->txproof,&proof[0],ptr->txprooflen); - return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); + flag = 1; + break; } } + if ( flag != 0 ) + { + set setTxids; + CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); + setTxids.insert(txid); + CMerkleBlock mb(block, setTxids); + ssMB << mb; + std::vector proof(ssMB.begin(), ssMB.end()); + ptr->txprooflen = (int32_t)proof.size(); + ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); + memcpy(ptr->txproof,&proof[0],ptr->txprooflen); + return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); + } + } + return(-1); +} + +int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) +{ + CBlockIndex *pindex; + if ( (pindex= komodo_chainactive(height)) != 0 ) + { + hdr->nVersion = pindex->nVersion; + hdr->hashPrevBlock = pindex->hashPrevBlock; + hdr->hashMerkleRoot = pindex->hashMerkleRoot; + hdr->hashFinalSaplingRoot = pindex->hashFinalSaplingRoot; + hdr->nTime = pindex->nTime; + hdr->nBits = pindex->nBits; + hdr->nNonce = pindex->nNonce; + memcpy(hdr->nSolution,pindex->nSolution,sizeof(hdr->nSolution)); + return(sizeof(*hdr)); } return(-1); } int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) { - int32_t len = 0; - return(len); + int32_t i; + ptr->prevht = prevht; + ptr->nextht = nextht; + ptr->numhdrs = (nextht - prevht + 1); + ptr->hdrs = (struct NSPV_equihdr *)calloc(ptr->numhdrs,sizeof(*ptr->hdrs)); + for (i=0; inumhdrs; i++) + { + if ( NSPV_setequihdr(&ptr->hdrs[i],prevht+i) < 0 ) + { + free(ptr->hdrs); + return(-1); + } + } + ptr->prevtxid = NSPV_getnotarization_txid(&ptr->prevtxidht,prevht); + ptr->prevntz = NSPV_getrawtx(&ptr->prevlen,ptr->prevtxid); + ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); + ptr->nextntz = NSPV_getrawtx(&ptr->nextlen,ptr->nexttxid); + return(sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); } int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) @@ -558,15 +639,17 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( prevht != 0 && nextht != 0 && nextht >= prevht ) { memset(&P,0,sizeof(P)); - slen = NSPV_getntzsproofresp(&P,prevht,nextht); - response.resize(1 + slen); - response[0] = NSPV_NTZPROOFRESP; - if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) + if ( (slen= NSPV_getntzsproofresp(&P,prevht,nextht)) > 0 ) { - pfrom->PushMessage("nSPV",response); - pfrom->lastproof = timestamp; + response.resize(1 + slen); + response[0] = NSPV_NTZPROOFRESP; + if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->lastproof = timestamp; + } + NSPV_ntzsproofresp_purge(&P); } - NSPV_ntzsproofresp_purge(&P); } } } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 028bc4dc2..63531f7fe 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -392,6 +392,30 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in return(0); } +int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height) +{ + struct notarized_checkpoint *np; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; + memset(nps,0,sizeof(*nps)*2); + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + { + if ( sp->NUM_NPOINTS > 0 ) + { + for (i=0; iNUM_NPOINTS; i++) + { + np = &sp->NPOINTS[i]; + if ( np->nHeight <= height ) + nps[0] = np; + else + { + nps[1] = np; + return(0); + } + } + } + } + return(-1); +} + int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp) { struct notarized_checkpoint *np = 0; int32_t i=0,flag = 0; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; From 119cbe5f3e883ca665d4ce0d5a381d58cde3cc96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 06:24:04 -1100 Subject: [PATCH 072/659] Syntax --- src/komodo_nSPV.h | 14 ++++++++++++-- src/komodo_notary.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f5e3cb7d9..6057fb59f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -353,7 +353,15 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) { uint256 ntztxid; - *ntzheightp = height + 2; // random value; + if ( ntxheightp == 0 ) // search consecutive blocks + { + *ntzheightp = height + 1; + // iterate + } + else + { + // check *ntzheightp + } // find notarization for height, return its txid and set *ntzheightp fprintf(stderr,"implement NSPV_getnotarization_txid\n"); return(ntztxid); @@ -367,6 +375,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) ptr->height = pindex->GetHeight(); ptr->blockhash = pindex->GetBlockHash(); ptr->notarization.height = komodo_notarized_height(&prevMoMheight,&ptr->notarization.blockhash,&ptr->notarization.othertxid); + ptr->notarization.txidheight = 0; ptr->notarization.txid = NSPV_getnotarization_txid(&ptr->notarization.txidheight,ptr->notarization.height); return(sizeof(*ptr)); } else return(-1); @@ -424,6 +433,7 @@ int32_t NSPV_npextract(struct NSPV_ntz *ptr,struct notarized_checkpoint *np) ptr->height = np->notarized_height; ptr->txidheight = np->nHeight; ptr->othertxid = np->notarized_desttxid; + ntzheight = ptr->txidheight; ptr->txid = NSPV_getnotarization_txid(&ntzheight,ptr->height); if ( ntzheight != ptr->txidheight ) { @@ -451,7 +461,7 @@ int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) return(sizeof(*ptr)); } -uint8_t *NSPV_getrawtx(uint256 &hashBlock,int32_t *txlenp,uint256 txid) +uint8_t *NSPV_getrawtx(uint256 &hashBlock,int16_t *txlenp,uint256 txid) { CTransaction tx; uint8_t *rawtx = 0; *txlenp = 0; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 63531f7fe..a80e035bd 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -394,7 +394,7 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height) { - struct notarized_checkpoint *np; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; + int32_t i; struct notarized_checkpoint *np; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; memset(nps,0,sizeof(*nps)*2); if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { From 6acf529efdd0c922dd352a7c19fd18989ef28354 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 06:28:13 -1100 Subject: [PATCH 073/659] Syntax --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 6057fb59f..d53f00635 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -353,7 +353,7 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) { uint256 ntztxid; - if ( ntxheightp == 0 ) // search consecutive blocks + if ( ntzheightp == 0 ) // search consecutive blocks { *ntzheightp = height + 1; // iterate @@ -461,7 +461,7 @@ int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) return(sizeof(*ptr)); } -uint8_t *NSPV_getrawtx(uint256 &hashBlock,int16_t *txlenp,uint256 txid) +uint8_t *NSPV_getrawtx(uint256 &hashBlock,uptr->notarization.txidheightint16_t *txlenp,uint256 txid) { CTransaction tx; uint8_t *rawtx = 0; *txlenp = 0; From 9a4243e2bfb97bfa1548a36ec1c334646e71e29e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 06:29:37 -1100 Subject: [PATCH 074/659] Syntax --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d53f00635..67ef28246 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -461,7 +461,7 @@ int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) return(sizeof(*ptr)); } -uint8_t *NSPV_getrawtx(uint256 &hashBlock,uptr->notarization.txidheightint16_t *txlenp,uint256 txid) +uint8_t *NSPV_getrawtx(uint256 &hashBlock,int16_t *txlenp,uint256 txid) { CTransaction tx; uint8_t *rawtx = 0; *txlenp = 0; From 8cfd799b29145f264d9960f6e08ed2a3829b79b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 06:31:03 -1100 Subject: [PATCH 075/659] Syntax --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 67ef28246..ee400e3c8 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -461,7 +461,7 @@ int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) return(sizeof(*ptr)); } -uint8_t *NSPV_getrawtx(uint256 &hashBlock,int16_t *txlenp,uint256 txid) +uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) { CTransaction tx; uint8_t *rawtx = 0; *txlenp = 0; From 031455e9b0669fdb1c0e8670d156b443e7f4849a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 06:37:31 -1100 Subject: [PATCH 076/659] Syntax --- src/komodo_nSPV.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index ee400e3c8..b868c3ad3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -532,15 +532,15 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) { int32_t i; - ptr->prevht = prevht; - ptr->nextht = nextht; - ptr->numhdrs = (nextht - prevht + 1); - ptr->hdrs = (struct NSPV_equihdr *)calloc(ptr->numhdrs,sizeof(*ptr->hdrs)); - for (i=0; inumhdrs; i++) + ptr->prevtxidht = prevht; + ptr->nexttxidht = nextht; + ptr->common.numhdrs = (nextht - prevht + 1); + ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); + for (i=0; icommon.numhdrs; i++) { - if ( NSPV_setequihdr(&ptr->hdrs[i],prevht+i) < 0 ) + if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) { - free(ptr->hdrs); + free(ptr->common.hdrs); return(-1); } } From 42cfe3265b1ebbe3277df7b963061bf02442b4ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 06:41:05 -1100 Subject: [PATCH 077/659] Syntax --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b868c3ad3..9f116e7aa 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -282,7 +282,7 @@ struct NSPV_ntzsproofresp { struct NSPV_ntzproofshared common; uint256 prevtxid,nexttxid; - uint32_t pad32,prevtxidht,nexttxidht; + int32_t pad32,prevtxidht,nexttxidht; uint16_t prevlen,nextlen; uint8_t *prevntz,*nextntz; }; From 29bdb27225b215a78284a6fb31a5c084fc9ac240 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 06:46:25 -1100 Subject: [PATCH 078/659] Syntax --- src/komodo_nSPV.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9f116e7aa..8126361e3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -523,7 +523,7 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) hdr->nTime = pindex->nTime; hdr->nBits = pindex->nBits; hdr->nNonce = pindex->nNonce; - memcpy(hdr->nSolution,pindex->nSolution,sizeof(hdr->nSolution)); + memcpy(hdr->nSolution,&pindex->nSolution[0],sizeof(hdr->nSolution)); return(sizeof(*hdr)); } return(-1); @@ -531,7 +531,7 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) { - int32_t i; + int32_t i; uint256 hashBlock; ptr->prevtxidht = prevht; ptr->nexttxidht = nextht; ptr->common.numhdrs = (nextht - prevht + 1); @@ -545,9 +545,9 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 } } ptr->prevtxid = NSPV_getnotarization_txid(&ptr->prevtxidht,prevht); - ptr->prevntz = NSPV_getrawtx(&ptr->prevlen,ptr->prevtxid); + ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevlen,ptr->prevtxid); ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); - ptr->nextntz = NSPV_getrawtx(&ptr->nextlen,ptr->nexttxid); + ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nextlen,ptr->nexttxid); return(sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); } From 1a16cdc29c4aebb6ee62d27d7ef7364aeba92b64 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 06:48:44 -1100 Subject: [PATCH 079/659] Pprev --- src/komodo_nSPV.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 8126361e3..75d7ff2bb 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -517,7 +517,9 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) if ( (pindex= komodo_chainactive(height)) != 0 ) { hdr->nVersion = pindex->nVersion; - hdr->hashPrevBlock = pindex->hashPrevBlock; + if ( pindex->pprev == 0 ) + return(-1); + hdr->hashPrevBlock = pindex->pprev->GetBlockHash(); hdr->hashMerkleRoot = pindex->hashMerkleRoot; hdr->hashFinalSaplingRoot = pindex->hashFinalSaplingRoot; hdr->nTime = pindex->nTime; From bc89c1de30d3c40ddb75ed82f67e41109b87ad33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 07:03:28 -1100 Subject: [PATCH 080/659] -prints --- src/main.cpp | 3 ++- src/net.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f214eaa5f..5b62f5747 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7052,7 +7052,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { const CChainParams& chainparams = Params(); LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); -fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); + if ( KOMODO_NSPV != 0 ) + fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); diff --git a/src/net.h b/src/net.h index dce52aa8b..dc21d1133 100644 --- a/src/net.h +++ b/src/net.h @@ -463,7 +463,7 @@ public: void PushMessage(const char* pszCommand) { - fprintf(stderr,"push.(%s)\n",pszCommand); + //fprintf(stderr,"push.(%s)\n",pszCommand); try { BeginMessage(pszCommand); @@ -479,7 +479,7 @@ public: template void PushMessage(const char* pszCommand, const T1& a1) { - fprintf(stderr,"push.(%s)\n",pszCommand); + //fprintf(stderr,"push.(%s)\n",pszCommand); try { BeginMessage(pszCommand); From 00fb6f3169e039a983b4dec5d579f327b2a05529 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 07:24:21 -1100 Subject: [PATCH 081/659] +print --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 75d7ff2bb..2423b4919 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -607,6 +607,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req coinaddr[request[1]] = 0; memset(&U,0,sizeof(U)); slen = NSPV_getaddressutxos(&U,coinaddr); + printf("getaddressutxos.(%s) slen.%d\n",coinaddr,slen); response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) From d1c66a47aeb2e9d013daf1f17cc2cb3c3686b848 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 07:27:59 -1100 Subject: [PATCH 082/659] Test --- src/komodo_nSPV.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 2423b4919..fa02fe187 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -836,7 +836,7 @@ void komodo_nSPV(CNode *pto) if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > pto->lastutxos + ASSETCHAINS_BLOCKTIME ) { // get utxo since lastheight - if ( (rand() % 100) < 10 ) + //if ( (rand() % 100) < 10 ) { char coinaddr[64]; int32_t slen; Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG); @@ -848,6 +848,7 @@ void komodo_nSPV(CNode *pto) request[1] = slen; memcpy(&request[2],coinaddr,slen); NSPV_lastutxos = pto->lastutxos = timestamp; + fprintf(stderr,"request address %s\n",coinaddr); pto->PushMessage("getnSPV",request); } } From c3343e237e2770a665dcc75c87d6e30033dc09ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 20:36:31 -1100 Subject: [PATCH 083/659] Getinfo, login, listunspent, spentinfo rpc calls --- src/komodo_defs.h | 1 + src/komodo_nSPV.h | 333 ++++++++++++++++++++++++++++------------- src/net.h | 2 +- src/rpc/server.cpp | 6 + src/rpc/server.h | 5 + src/wallet/rpcdump.cpp | 37 +++++ 6 files changed, 275 insertions(+), 109 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index cef5c4d1c..6ac777898 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -337,5 +337,6 @@ uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 int32_t komodo_currentheight(); int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height); +uint256 Parseuint256(const char *hexstr); #endif diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fa02fe187..64d432717 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -575,13 +575,14 @@ int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request { - int32_t len,slen; std::vector response; uint32_t timestamp; - timestamp = (uint32_t)time(NULL); + int32_t len,slen,ind; std::vector response; uint32_t timestamp = (uint32_t)time(NULL); if ( (len= request.size()) > 0 ) { + if ( (ind= request[0]>>1) >= sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes) ) + ind = (int32_t)(sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes)) - 1; if ( request[0] == NSPV_INFO ) // info { - if ( len == 1 && timestamp > pfrom->lastinfo + ASSETCHAINS_BLOCKTIME/2 ) + if ( len == 1 && timestamp > pfrom->prevtimes[ind] + ASSETCHAINS_BLOCKTIME/2 ) { struct NSPV_inforesp I; memset(&I,0,sizeof(I)); @@ -591,14 +592,14 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req response[0] = NSPV_INFORESP; NSPV_rwinforesp(1,&response[1],&I); pfrom->PushMessage("nSPV",response); - pfrom->lastinfo = timestamp; + pfrom->prevtimes[ind] = timestamp; NSPV_inforesp_purge(&I); } } } else if ( request[0] == NSPV_UTXOS ) { - if ( timestamp > pfrom->lastutxos + ASSETCHAINS_BLOCKTIME/2 ) + if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_utxosresp U; char coinaddr[64]; if ( len < 64 && request[1] == len-2 ) @@ -606,43 +607,47 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memcpy(coinaddr,&request[2],request[1]); coinaddr[request[1]] = 0; memset(&U,0,sizeof(U)); - slen = NSPV_getaddressutxos(&U,coinaddr); - printf("getaddressutxos.(%s) slen.%d\n",coinaddr,slen); - response.resize(1 + slen); - response[0] = NSPV_UTXOSRESP; - if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) + if ( (slen= NSPV_getaddressutxos(&U,coinaddr)) > 0 ) { - pfrom->PushMessage("nSPV",response); - pfrom->lastutxos = timestamp; + printf("getaddressutxos.(%s) slen.%d\n",coinaddr,slen); + response.resize(1 + slen); + response[0] = NSPV_UTXOSRESP; + if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_utxosresp_purge(&U); } - NSPV_utxosresp_purge(&U); } } } else if ( request[0] == NSPV_NTZS ) { - if ( timestamp > pfrom->lastntzs ) + if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_ntzsresp N; int32_t height; if ( len == 1+sizeof(height) ) { iguana_rwnum(0,&request[1],sizeof(height),&height); memset(&N,0,sizeof(N)); - slen = NSPV_getntzsresp(&N,height); - response.resize(1 + slen); - response[0] = NSPV_NTZSRESP; - if ( NSPV_rwntzsresp(1,&response[1],&N) == slen ) + if ( (slen= NSPV_getntzsresp(&N,height)) > 0 ) { - pfrom->PushMessage("nSPV",response); - pfrom->lastntzs = timestamp; + response.resize(1 + slen); + response[0] = NSPV_NTZSRESP; + if ( NSPV_rwntzsresp(1,&response[1],&N) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_ntzsresp_purge(&N); } - NSPV_ntzsresp_purge(&N); } } } else if ( request[0] == NSPV_NTZPROOF ) { - if ( timestamp > pfrom->lastproof ) + if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_ntzsproofresp P; int32_t prevht,nextht; if ( len == 1+sizeof(prevht)+sizeof(nextht) ) @@ -659,7 +664,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) { pfrom->PushMessage("nSPV",response); - pfrom->lastproof = timestamp; + pfrom->prevtimes[ind] = timestamp; } NSPV_ntzsproofresp_purge(&P); } @@ -669,7 +674,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } else if ( request[0] == NSPV_TXPROOF ) { - if ( timestamp > pfrom->lastproof ) + if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_txproof P; uint256 txid; int32_t height; if ( len == 1+sizeof(txid)+sizeof(height) ) @@ -677,21 +682,23 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwnum(0,&request[1],sizeof(height),&height); iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); memset(&P,0,sizeof(P)); - slen = NSPV_gettxproof(&P,txid,height); - response.resize(1 + slen); - response[0] = NSPV_TXPROOFRESP; - if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) + if ( (slen= NSPV_gettxproof(&P,txid,height)) > 0 ) { - pfrom->PushMessage("nSPV",response); - pfrom->lastproof = timestamp; + response.resize(1 + slen); + response[0] = NSPV_TXPROOFRESP; + if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_txproof_purge(&P); } - NSPV_txproof_purge(&P); } } } else if ( request[0] == NSPV_SPENTINFO ) { - if ( timestamp > pfrom->lastspent ) + if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_spentinfo S; int32_t vout; uint256 txid; if ( len == 1+sizeof(txid)+sizeof(vout) ) @@ -706,7 +713,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( NSPV_rwspentinfo(1,&response[1],&S) == slen ) { pfrom->PushMessage("nSPV",response); - pfrom->lastspent = timestamp; + pfrom->prevtimes[ind] = timestamp; } NSPV_spentinfo_purge(&S); } @@ -716,12 +723,179 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } } -// on nSPV client -uint32_t NSPV_lastinfo,NSPV_lastutxos; +// nSPV client +uint32_t NSPV_lastinfo,NSPV_lastutxos,NSPV_logintime; +char NSPV_wifstr[64]; +std::string NSPV_address; int32_t NSPV_numutxos,NSPV_numspends; +struct NSPV_inforesp NSPV_inforesult; +struct NSPV_utxosresp NSPV_utxosresult; struct NSPV_utxo *NSPV_utxos; struct NSPV_spentinfo *NSPV_spends; +CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint32_t mask,int32_t ind) +{ + int32_t flag = 0; uint32_t timestamp = (uint32_t)time(NULL); + if ( pnode == 0 ) + { + LOCK(cs_vNodes); + BOOST_FOREACH(CNode *pnode,vNodes) + { + if ( pnode->hSocket == INVALID_SOCKET ) + continue; + if ( (pnode->nServices & mask) == mask && timestamp > pnode->prevtimes[ind] ) + { + flag = 1; + break; + } + } + } else flag = 1; + if ( pnode != 0 ) + { + std::vector request; + request.resize(len); + memcpy(&request[0],msg,len); + pnode->PushMessage("getnSPV",request); + pnode->prevtimes[ind] = timestamp; + return(pnode); + } + return(0); +} + +void komodo_NSPV_spentinfoclear() +{ + if ( NSPV_spends != 0 ) + free(NSPV_spends); + NSPV_spends = 0; + NSPV_numspends = 0; +} + +UniValue NSPV_spentinfo_json(struct NSPV_spentinfo *ptr) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + result.push_back(Pair("txid",ptr->txid.GetHex())); + result.push_back(Pair("vout",(int64_t)ptr->vout)); + result.push_back(Pair("spentheight",(int64_t)ptr->spent.height)); + result.push_back(Pair("spenttxid",ptr->spent.txid.GetHex())); + result.push_back(Pair("spentvini",(int64_t)ptr->spentvini)); + result.push_back(Pair("spenttxlen",(int64_t)ptr->spent.txlen)); + result.push_back(Pair("spenttxprooflen",(int64_t)ptr->spent.txprooflen)); + return(result); +} + +UniValue NSPV_ntz_json(struct NSPV_ntz *ptr) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("notarized_height",(int64_t)ptr->height)); + result.push_back(Pair("notarized_blockhash",ptr->blockhash.GetHex())); + result.push_back(Pair("notarization_txid",ptr->txid.GetHex())); + result.push_back(Pair("notarization_txidheight",(int64_t)ptr->txidheight)); + result.push_back(Pair("notarization_desttxid",ptr->othertxid.GetHex())); + return(result); +} + +UniValue NSPV_getinfo() +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + result.push_back(Pair("height",(int64_t)ptr->height)); + result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); + result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); + return(result); +} + +UniValue NSPV_utxoresp_json(struct NSPV_utxosresp *utxos,int32_t numutxos) +{ + UniValue array(UniValue::VARR); int32_t i; + for (i=0; iutxos,ptr->numutxos))); + result.push_back(Pair("height",(int64_t)ptr->height)); + result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); + result.push_back(Pair("balance",AmountFromValue(ptr->total))); + result.push_back(Pair("interest",AmountFromValue(ptr->interest))); + return(result); +} + +UniValue NSPV_spentinfo(uint256 txid,int32_t vout) +{ + uint8_t msg[64]; struct NSPV_spentinfo I; int32_t i,len = 0; + for (i=0; i>1) != 0 ) + usleep(250000); + for (i=0; i>1) != 0 ) + usleep(250000); + } + if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height ) + { + return(NSPV_utxosresp_json(NSPV_utxosresult)); + } + result.push_back(Pair("result","error")); + result.push_back(Pair("error","no utxos result")); + return(result); +} + void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response { int32_t len; uint32_t timestamp = (uint32_t)time(NULL); @@ -730,11 +904,12 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r switch ( response[0] ) { case NSPV_INFORESP: - // deser and display - fprintf(stderr,"got info response %u size.%d\n",timestamp,(int32_t)response.size()); // update current height and ntrz status + NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); + fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status break; case NSPV_UTXOSRESP: - // deser and process + NSPV_utxosresp_purge(&NSPV_utxosresult); + NSPV_rwutxosresp(0,&response[1],&NSPV_utxosresult); fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos list break; case NSPV_NTZSRESP: @@ -755,50 +930,18 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r } } -void komodo_NSPV_spentinfoclear() +void komodo_nSPV(CNode *pto) // polling loop from SendMessages { - if ( NSPV_spends != 0 ) - free(NSPV_spends); - NSPV_spends = 0; - NSPV_numspends = 0; -} - -struct NSPV_spentinfo komodo_NSPV_spentinfo(uint256 txid,int32_t vout) // just a primitive example of how to add new rpc to p2p msg -{ - std::vector request; struct NSPV_spentinfo I; int32_t i,numsent = 0; uint32_t timestamp; - timestamp = (uint32_t)time(NULL); - for (i=0; i NSPV_logintime+60 ) { - I = NSPV_spends[i]; - if ( I.txid == txid && I.vout == vout ) - return(I); + fprintf(stderr,"scrub wif from NSPV memory\n"); + memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); + NSPV_logintime = 0; } - LOCK(cs_vNodes); - BOOST_FOREACH(CNode *pnode, vNodes) - { - if ( pnode->hSocket == INVALID_SOCKET ) - continue; - if ( (pnode->nServices & NODE_SPENTINDEX) != 0 && timestamp > pnode->lastspent ) - { - if ( 0 ) // submit actual request - { - request.resize(1); - request[0] = NSPV_SPENTINFO; - pnode->lastspent = timestamp; - pnode->PushMessage("getnSPV",request); - if ( ++numsent >= 3 ) - break; - } - } - } -} - -void komodo_nSPV(CNode *pto) -{ - std::vector request; int32_t i; uint32_t timestamp = (uint32_t)time(NULL); if ( (pto->nServices & NODE_NSPV) == 0 ) return; - if ( timestamp > pto->lastntzs || timestamp > pto->lastproof ) + /*if ( timestamp > pto->lastntzs || timestamp > pto->lastproof ) { for (i=0; i NSPV_lastutxos + ASSETCHAINS_BLOCKTIME/2 ) + }*/ + if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + ASSETCHAINS_BLOCKTIME/2 ) { - if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > pto->lastutxos + ASSETCHAINS_BLOCKTIME ) + if ( (rand() % 100) < 10 ) // randomize which peer to query { - // get utxo since lastheight - //if ( (rand() % 100) < 10 ) - { - char coinaddr[64]; int32_t slen; - Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG); - slen = (int32_t)strlen(coinaddr); - if ( slen < 64 ) - { - request.resize(1 + 1 + slen); - request[0] = NSPV_UTXOS; - request[1] = slen; - memcpy(&request[2],coinaddr,slen); - NSPV_lastutxos = pto->lastutxos = timestamp; - fprintf(stderr,"request address %s\n",coinaddr); - pto->PushMessage("getnSPV",request); - } - } - } - } - if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->lastinfo + ASSETCHAINS_BLOCKTIME ) - { - if ( (rand() % 100) < 10 ) - { - // query current height, blockhash, notarization info - request.resize(1); - request[0] = NSPV_INFO; - NSPV_lastinfo = pto->lastinfo = timestamp; - pto->PushMessage("getnSPV",request); + msg[len++] = NSPV_INFO; + NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); } } } diff --git a/src/net.h b/src/net.h index dc21d1133..0b8dcd901 100644 --- a/src/net.h +++ b/src/net.h @@ -276,7 +276,7 @@ public: int64_t nLastRecv; int64_t nTimeConnected; int64_t nTimeOffset; - uint32_t lastutxos,lastinfo,lastntzs,lastproof,lastspent; + uint32_t prevtimes[8]; CAddress addr; std::string addrName; CService addrLocal; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 75360fd35..937ae0632 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -416,6 +416,12 @@ static const CRPCCommand vRPCCommands[] = { "FSM", "FSMlist", &FSMlist, true }, { "FSM", "FSMinfo", &FSMinfo, true }, + // fsm + { "nSPV", "nspv_getinfo", &nspv_getinfo, true }, + { "nSPV", "nspv_login", &nspv_login, true }, + { "nSPV", "nspv_listunspent", &nspv_listunspent, true }, + { "nSPV", "nspv_spentinfo", &nspv_spentinfo, true }, + // rewards { "rewards", "rewardslist", &rewardslist, true }, { "rewards", "rewardsinfo", &rewardsinfo, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index d447d2472..bc895ee53 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -455,6 +455,11 @@ extern UniValue importgatewaypendingdeposits(const UniValue& params, bool fHelp) extern UniValue importgatewaypendingwithdraws(const UniValue& params, bool fHelp); extern UniValue importgatewayprocessed(const UniValue& params, bool fHelp); +extern UniValue nspv_getinfo(const UniValue& params, bool fHelp); +extern UniValue nspv_login(const UniValue& params, bool fHelp); +extern UniValue nspv_listunspent(const UniValue& params, bool fHelp); +extern UniValue nspv_spentinfo(const UniValue& params, bool fHelp); + extern UniValue getblocksubsidy(const UniValue& params, bool fHelp); extern UniValue z_exportkey(const UniValue& params, bool fHelp); // in rpcdump.cpp diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index d35b09a96..f133b1c07 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -971,3 +971,40 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) return EncodeViewingKey(vk); } + +UniValue NSPV_getinfo(); +UniValue NSPV_login(char *wifstr); +UniValue NSPV_addressutxos(char *coinaddr); +UniValue NSPV_spentinfo(uint256 txid,int32_t vout); + +UniValue nspv_getinfo(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() != 0 ) + throw runtime_error("nspv_getinfo\n"); + return(NSPV_getinfo()); +} + +UniValue nspv_login(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() != 1 ) + throw runtime_error("nspv_login wif\n"); + return(NSPV_login((char *)params[0].get_str().c_str())); +} + +UniValue nspv_listunspent(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() != 1 ) + throw runtime_error("nspv_listunspent address\n"); + return(NSPV_addressutxos((char *)params[0].get_str().c_str())); +} + +UniValue nspv_spentinfo(const UniValue& params, bool fHelp) +{ + uint256 txid; int32_t vout; + if ( fHelp || params.size() != 2 ) + throw runtime_error("nspv_spentinfo txid vout\n"); + txid = Parseuint256((char *)params[0].get_str().c_str()); + vout = atoi((char *)params[1].get_str().c_str()); + return(NSPV_spentinfo(txid,vout)); +} + From eb851fe8833e041e0df6d5f573fc8d0e36313cc2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 20:53:31 -1100 Subject: [PATCH 084/659] Syntax --- src/komodo_nSPV.h | 18 +++++++++--------- src/main.cpp | 17 +++++------------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 64d432717..fccdf7280 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -799,24 +799,24 @@ UniValue NSPV_getinfo() { UniValue result(UniValue::VOBJ); result.push_back(Pair("result","success")); - result.push_back(Pair("height",(int64_t)ptr->height)); - result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); - result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); + result.push_back(Pair("height",(int64_t)NSPV_inforesult.height)); + result.push_back(Pair("chaintip",NSPV_inforesult.blockhash.GetHex())); + result.push_back(Pair("notarization",NSPV_ntz_json(&NSPV_inforesult.notarization))); return(result); } -UniValue NSPV_utxoresp_json(struct NSPV_utxosresp *utxos,int32_t numutxos) +UniValue NSPV_utxoresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) { UniValue array(UniValue::VARR); int32_t i; for (i=0; i payload; - vRecv >> payload; - komodo_nSPVresp(pfrom,payload); - return(true); - } - fprintf(stderr,"ignore message %s\n",strCommand.c_str()); + std::vector payload; + vRecv >> payload; + komodo_nSPVresp(pfrom,payload); return(true); } @@ -8228,11 +8223,9 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } state.fShouldBan = false; } + komodo_nSPV(pto); if ( KOMODO_NSPV != 0 ) - { - komodo_nSPV(pto); return(true); - } BOOST_FOREACH(const CBlockReject& reject, state.rejects) pto->PushMessage("reject", (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock); state.rejects.clear(); From f443435d003c406dd4897082a60bbe7d6f64dfe6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 20:56:12 -1100 Subject: [PATCH 085/659] Syntax --- src/komodo_nSPV.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fccdf7280..a0c078c77 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -810,7 +810,7 @@ UniValue NSPV_utxoresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) UniValue array(UniValue::VARR); int32_t i; for (i=0; iutxos,ptr->numutxos))); - result.push_back(Pair("height",(int64_t)ptr->height)); + result.push_back(Pair("height",(int64_t)ptr->nodeheight)); result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); result.push_back(Pair("balance",AmountFromValue(ptr->total))); result.push_back(Pair("interest",AmountFromValue(ptr->interest))); @@ -866,7 +866,7 @@ UniValue NSPV_login(char *wifstr) NSPV_logintime = (uint32_t)time(NULL); result.push_back(Pair("result","success")); result.push_back(Pair("status","wif will expire in 60 seconds")); - CKey key = DecodeSecret(strSecret); + CKey key = DecodeSecret(wifstr); CPubKey pubkey = key.GetPubKey(); //assert(key.VerifyPubKey(pubkey)); CKeyID vchAddress = pubkey.GetID(); @@ -880,7 +880,7 @@ UniValue NSPV_addressutxos(char *coinaddr) UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t slen,len = 0; if ( NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { - slen = (int32_t)strlen(coinaddr) + slen = (int32_t)strlen(coinaddr); msg[len++] = NSPV_UTXOS; msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; @@ -889,7 +889,7 @@ UniValue NSPV_addressutxos(char *coinaddr) } if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height ) { - return(NSPV_utxosresp_json(NSPV_utxosresult)); + return(NSPV_utxosresp_json(&NSPV_utxosresult)); } result.push_back(Pair("result","error")); result.push_back(Pair("error","no utxos result")); From c435986dd27936e6b0afaa2529c31956fa054318 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 20:57:42 -1100 Subject: [PATCH 086/659] extern CAmount AmountFromValue(const UniValue& value); --- src/komodo_nSPV.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a0c078c77..3c5d79b22 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -724,6 +724,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } // nSPV client +extern CAmount AmountFromValue(const UniValue& value); + uint32_t NSPV_lastinfo,NSPV_lastutxos,NSPV_logintime; char NSPV_wifstr[64]; std::string NSPV_address; From a0d5a1f612a8679e6c46be7015b53a01a7eb35ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 21:06:10 -1100 Subject: [PATCH 087/659] uint256 Parseuint256(const char *hexstr); --- src/wallet/rpcdump.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index f133b1c07..263145320 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -976,6 +976,7 @@ UniValue NSPV_getinfo(); UniValue NSPV_login(char *wifstr); UniValue NSPV_addressutxos(char *coinaddr); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); +uint256 Parseuint256(const char *hexstr); UniValue nspv_getinfo(const UniValue& params, bool fHelp) { From 90b1bdbedc678f0e798a19bec8d4769928e610f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 21:22:50 -1100 Subject: [PATCH 088/659] Wif err check --- src/komodo_nSPV.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3c5d79b22..18fa5afdc 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -724,7 +724,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } // nSPV client -extern CAmount AmountFromValue(const UniValue& value); +CAmount AmountFromValue(const UniValue& value); +int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); uint32_t NSPV_lastinfo,NSPV_lastutxos,NSPV_logintime; char NSPV_wifstr[64]; @@ -862,7 +863,14 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) UniValue NSPV_login(char *wifstr) { - UniValue result(UniValue::VOBJ); char coinaddr[64]; + UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[64]; int32_t len; + if ( (len= bitcoin_base58decode(data,wifstr)) != 32 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid wif")); + result.push_back(Pair("len",(int64_t)len)); + return(result); + } memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); strncpy(NSPV_wifstr,wifstr,sizeof(NSPV_wifstr)-1); NSPV_logintime = (uint32_t)time(NULL); From dd0a99e2d9801dc48c18986dd0467ae84fa1c1d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 21:26:01 -1100 Subject: [PATCH 089/659] Decoded wif 38 bytes --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 18fa5afdc..f2a41ff48 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -864,7 +864,7 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) UniValue NSPV_login(char *wifstr) { UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[64]; int32_t len; - if ( (len= bitcoin_base58decode(data,wifstr)) != 32 ) + if ( (len= bitcoin_base58decode(data,wifstr)) != 38 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid wif")); From 27d8ccf5544a34c5316a73adda4227df15b829e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 21:31:03 -1100 Subject: [PATCH 090/659] Compressed and uncompressed support --- src/komodo_nSPV.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f2a41ff48..a53488253 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -863,8 +863,11 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) UniValue NSPV_login(char *wifstr) { - UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[64]; int32_t len; - if ( (len= bitcoin_base58decode(data,wifstr)) != 38 ) + UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[64]; int32_t len,valid = 0; + len = bitcoin_base58decode(data,wifstr); + if ( (len == 38 && data[len-5] == 1) || (len == 37 && data[len-5] != 1) ) + valid = 1; + if ( valid == 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid wif")); From 80b50da29be6906db475f7dbb64c014cab7fbc4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 21:36:55 -1100 Subject: [PATCH 091/659] +print --- src/komodo_nSPV.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a53488253..642149cef 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -863,9 +863,9 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) UniValue NSPV_login(char *wifstr) { - UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[64]; int32_t len,valid = 0; + UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0; len = bitcoin_base58decode(data,wifstr); - if ( (len == 38 && data[len-5] == 1) || (len == 37 && data[len-5] != 1) ) + if ( strlen(wifstr) < 64 && (len == 38 && data[len-5] == 1) || (len == 37 && data[len-5] != 1) ) valid = 1; if ( valid == 0 ) { @@ -885,6 +885,10 @@ UniValue NSPV_login(char *wifstr) CKeyID vchAddress = pubkey.GetID(); NSPV_address = EncodeDestination(vchAddress); result.push_back(Pair("address",NSPV_address)); + result.push_back(Pair("pubkey",HexStr(pubkey))); + result.push_back(Pair("wifprefix",(int64_t)data[0])); + result.push_back(Pair("compressed",(int64_t)(data[len-5] == 1))); + memset(data,0,sizeof(data)); return(result); } From 5263d3c74de6675fd1221a49e4301d76e53e8b90 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 21:56:43 -1100 Subject: [PATCH 092/659] +print --- src/komodo_nSPV.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 642149cef..5114dc999 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -756,8 +756,9 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint32_t mask,int32_t ind) if ( pnode != 0 ) { std::vector request; - request.resize(len); + request.resize(len+1); memcpy(&request[0],msg,len); + fprintf(stderr,"pushmessage len.%d\n",len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; return(pnode); @@ -895,12 +896,19 @@ UniValue NSPV_login(char *wifstr) UniValue NSPV_addressutxos(char *coinaddr) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t slen,len = 0; + if ( bitcoin_base58decode(msg,coinaddr) != 25 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid address")); + return(result); + } if ( NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { slen = (int32_t)strlen(coinaddr); msg[len++] = NSPV_UTXOS; msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; + fprintf(stderr,"issue addressutxos.(%s)\n",coinaddr); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,NSPV_UTXOS>>1) != 0 ) usleep(250000); } From 165c26660917e563282b1a6720fd1511bf02442f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 22:06:43 -1100 Subject: [PATCH 093/659] Test --- src/komodo_nSPV.h | 11 ++++++++--- src/main.cpp | 23 ++++++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 5114dc999..2305e445a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -756,9 +756,9 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint32_t mask,int32_t ind) if ( pnode != 0 ) { std::vector request; - request.resize(len+1); + request.resize(len); memcpy(&request[0],msg,len); - fprintf(stderr,"pushmessage len.%d\n",len); + fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; return(pnode); @@ -902,8 +902,13 @@ UniValue NSPV_addressutxos(char *coinaddr) result.push_back(Pair("error","invalid address")); return(result); } - if ( NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) + if ( NSPV_inforesult.height == 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { + if ( NSPV_inforesult.height == 0 ) + { + msg[0] = NSPV_INFO; + NSPV_req(0,msg,1,NODE_NSPV,NSPV_INFO>>1); + } slen = (int32_t)strlen(coinaddr); msg[len++] = NSPV_UTXOS; msg[len++] = slen; diff --git a/src/main.cpp b/src/main.cpp index 4438aa08e..334d1f276 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7052,7 +7052,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { const CChainParams& chainparams = Params(); LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); - if ( KOMODO_NSPV != 0 ) + //if ( KOMODO_NSPV != 0 ) + if ( strCommand != "version" && strCommand != "verack" ) fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { @@ -7226,11 +7227,23 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); - if ( KOMODO_NSPV != 0 && (pfrom->nServices & NODE_NSPV) == 0 ) + if ( KOMODO_NSPV != 0 ) { - fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); - pfrom->fDisconnect = true; - return false; + if ( (pfrom->nServices & NODE_NSPV) == 0 ) + { + fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); + pfrom->fDisconnect = true; + return false; + } + } + else + { + if ( pfrom->nServices != 0 ) + { + fprintf(stderr,"debug mode, disconnect legacy peer.%d\n",pfrom->id); + pfrom->fDisconnect = true; + return false; + } } // Mark this node as currently connected, so we update its timestamp later. if (pfrom->fNetworkNode) { From fa46a6e347dd97aad72022ef2e0ae442de3c6c69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 22:12:35 -1100 Subject: [PATCH 094/659] Revert debug disconnect --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 334d1f276..d30213d6b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7236,7 +7236,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, return false; } } - else + else if ( (0) ) { if ( pfrom->nServices != 0 ) { From 057f1e39cdddc10c00c0a5a7c9d2777344e4a858 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 22:20:15 -1100 Subject: [PATCH 095/659] +print --- src/komodo_nSPV.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 2305e445a..ef665a45c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -736,7 +736,7 @@ struct NSPV_utxosresp NSPV_utxosresult; struct NSPV_utxo *NSPV_utxos; struct NSPV_spentinfo *NSPV_spends; -CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint32_t mask,int32_t ind) +CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t flag = 0; uint32_t timestamp = (uint32_t)time(NULL); if ( pnode == 0 ) @@ -751,6 +751,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint32_t mask,int32_t ind) flag = 1; break; } + else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)pnode->nServices,(long long)mask,timestamp,pnode->prevtimes[ind],ind); } } else flag = 1; if ( pnode != 0 ) @@ -913,7 +914,8 @@ UniValue NSPV_addressutxos(char *coinaddr) msg[len++] = NSPV_UTXOS; msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; - fprintf(stderr,"issue addressutxos.(%s)\n",coinaddr); + msg[len] = 0; + fprintf(stderr,"issue addressutxos.(%s) (%s)\n",coinaddr,(char *)&msg[2]); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,NSPV_UTXOS>>1) != 0 ) usleep(250000); } From 1f013df15670f8f96790858d9418136ac9350ab2 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 4 Jul 2019 11:23:55 +0200 Subject: [PATCH 096/659] Initial PegsCC implementation (#27) --- src/cc/CCPegs.h | 11 +- src/cc/CCinclude.h | 5 +- src/cc/CCtokens.cpp | 15 + src/cc/CCtx.cpp | 5 +- src/cc/CCutils.cpp | 5 +- src/cc/channels.cpp | 2 +- src/cc/heir_validate.h | 5 +- src/cc/import.cpp | 13 +- src/cc/pegs.cpp | 1228 ++++++++++++++++++++++++++++++++-- src/coins.cpp | 8 +- src/importcoin.cpp | 57 +- src/importcoin.h | 4 + src/komodo_globals.h | 2 +- src/komodo_utils.h | 40 +- src/main.cpp | 29 +- src/miner.cpp | 7 + src/primitives/transaction.h | 6 + src/rpc/rawtransaction.cpp | 2 +- src/rpc/server.cpp | 12 + src/rpc/server.h | 10 + src/txmempool.cpp | 5 + src/wallet/rpcwallet.cpp | 199 ++++++ 22 files changed, 1581 insertions(+), 89 deletions(-) diff --git a/src/cc/CCPegs.h b/src/cc/CCPegs.h index 8d2a268f1..e4d390d0e 100644 --- a/src/cc/CCPegs.h +++ b/src/cc/CCPegs.h @@ -22,6 +22,15 @@ bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom -UniValue PegsInfo(); +std::string PegsCreate(uint64_t txfee,int64_t amount,std::vector bindtxids); +std::string PegsFund(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount); +std::string PegsGet(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount); +std::string PegsRedeem(uint64_t txfee,uint256 pegstxid, uint256 tokenid); +std::string PegsLiquidate(uint64_t txfee,uint256 pegstxid, uint256 tokenid, uint256 liquidatetxid); +std::string PegsExchange(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount); +UniValue PegsAccountHistory(uint256 pegstxid); +UniValue PegsAccountInfo(uint256 pegstxid); +UniValue PegsWorstAccounts(uint256 pegstxid); +UniValue PegsInfo(uint256 pegstxid); #endif diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 1d8cf669e..2df5bc39f 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -79,6 +79,7 @@ one other technical note is that komodod has the insight-explorer extensions bui OPRETID_CHANNELSDATA = 0x14, OPRETID_HEIRDATA = 0x15, OPRETID_ROGUEGAMEDATA = 0x16, + OPRETID_PEGSDATA = 0x17, // non cc contract data: OPRETID_FIRSTNONCCDATA = 0x80, @@ -126,7 +127,7 @@ struct CCcontract_info // the same for tokens 1of2 keys cc char tokens1of2addr[64]; - CPubKey tokens1of2pk[2]; + CPubKey tokens1of2pk[2]; uint8_t tokens1of2priv[32]; // this is for spending from two additional 'unspendable' CC addresses of other eval codes // (that is, for spending from several cc contract 'unspendable' addresses): @@ -249,7 +250,7 @@ CC *MakeTokensCCcond1(uint8_t evalcode, CPubKey pk); CC *MakeTokensCCcond1(uint8_t evalcode, uint8_t evalcode2, CPubKey pk); bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk); bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); -void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, uint8_t *priv, char *coinaddr); int32_t CClib_initcp(struct CCcontract_info *cp,uint8_t evalcode); bool IsCCInput(CScript const& scriptSig); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 5f5e56ebb..c664fd49d 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -397,6 +397,21 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys /*<--not used, always true } } + //special check for 3 pubkey tx when spending from 1of2 CC address with on of pubkeys is global CC pubkey + struct CCcontract_info *cpEvalCode1,CEvalCode1; + cpEvalCode1 = CCinit(&CEvalCode1,evalCode1); + CPubKey pk=GetUnspendable(cpEvalCode1,0); + testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval1 pegscc cc1of2 pk[0]")) ); + testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval1 pegscc cc1of2 pk[1]")) ); + if (evalCode2!=0) + { + struct CCcontract_info *cpEvalCode2,CEvalCode2; + cpEvalCode2 = CCinit(&CEvalCode2,evalCode2); + CPubKey pk=GetUnspendable(cpEvalCode2,0); + testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval2 pegscc cc1of2 pk[0]")) ); + testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval2 pegscc cc1of2 pk[1]")) ); + } + // maybe it is single-eval or dual/three-eval token change? std::vector vinPubkeys, vinPubkeysUnfiltered; ExtractTokensCCVinPubkeys(tx, vinPubkeysUnfiltered); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 7435defbf..4a9eef911 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -96,6 +96,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran //This is a must to avoid hardfork change of validation in every CC, because there could be maximum one normal vin at the begining with current validation. for (i=0; itokens1of2addr, destaddr) == 0) { //fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr); - privkey = myprivkey; + privkey = cp->tokens1of2priv;//myprivkey; if (othercond1of2tokens == 0) // NOTE: if additionalEvalcode2 is not set then it is dual-eval cc else three-eval cc // TODO: verify evalcodes order if additionalEvalcode2 is not 0 diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 5de5ed0db..7d94a37a9 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -187,7 +187,7 @@ void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t * } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 cryptocondition vout: -void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2,uint8_t *priv,char *coinaddr) +void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, uint8_t *priv, char *coinaddr) { cp->coins1of2pk[0] = pk1; cp->coins1of2pk[1] = pk2; @@ -197,10 +197,11 @@ void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2,uint8_t // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 token cryptocondition vout // to get tokenaddr use GetTokensCCaddress() -void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *tokenaddr) +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, uint8_t *priv, char *tokenaddr) { cp->tokens1of2pk[0] = pk1; cp->tokens1of2pk[1] = pk2; + memcpy(cp->tokens1of2priv,priv,32); strcpy(cp->tokens1of2addr, tokenaddr); } diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 64bb95572..2d161675c 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -451,7 +451,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C mtx.vin.push_back(CTxIn(txid,0,CScript())); mtx.vin.push_back(CTxIn(txid,marker,CScript())); Myprivkey(myprivkey); - if (tokenid!=zeroid) CCaddrTokens1of2set(cp,srcpub,destpub,coinaddr); + if (tokenid!=zeroid) CCaddrTokens1of2set(cp,srcpub,destpub,myprivkey,coinaddr); else CCaddr1of2set(cp,srcpub,destpub,myprivkey,coinaddr); return totalinputs; } diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index a27dc3340..c7424bc16 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -98,8 +98,9 @@ public: } static void CCaddrCoinsOrTokens1of2set(struct CCcontract_info *cp, CPubKey ownerPubkey, CPubKey heirPubkey, char *coinaddr) { - - CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + uint8_t mypriv[32]; + Myprivkey(mypriv); + CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, mypriv, coinaddr); } }; diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 35b4f5405..aa2ea5d11 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -681,7 +681,7 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp return Invalid("invalid-params"); // Control all aspects of this transaction // It should not be at all malleable - if (MakeImportCoinTransaction(proof, burnTx, payouts, importTx.nExpiryHeight).GetHash() != importTx.GetHash()) // ExistsImportTombstone prevents from duplication + if (ASSETCHAINS_SELFIMPORT!="PEGSCC" && MakeImportCoinTransaction(proof, burnTx, payouts, importTx.nExpiryHeight).GetHash() != importTx.GetHash()) // ExistsImportTombstone prevents from duplication return Invalid("non-canonical"); // burn params if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash, rawproof)) @@ -736,10 +736,17 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp else if ( UnmarshalBurnTx(burnTx,srcaddr,receipt)==0 || CheckCODAimport(importTx,burnTx,payouts,srcaddr,receipt) < 0 ) return Invalid("CODA-import-failure"); } + else if ( targetSymbol == "PEGSCC" ) + { + if ( ASSETCHAINS_SELFIMPORT != "PEGSCC" ) + return Invalid("PEGSCC-import-when-not PEGSCC"); + // else if ( CheckPUBKEYimport(merkleBranchProof,rawproof,burnTx,payouts) < 0 ) + // return Invalid("PEGSCC-import-failure"); + } else if ( targetSymbol == "PUBKEY" ) { if ( ASSETCHAINS_SELFIMPORT != "PUBKEY" ) - return Invalid("PUBKEY-import-when-notPUBKEY"); + return Invalid("PUBKEY-import-when-not PUBKEY"); else if ( CheckPUBKEYimport(merkleBranchProof,rawproof,burnTx,payouts) < 0 ) return Invalid("PUBKEY-import-failure"); } @@ -747,7 +754,7 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp { if ( targetSymbol != ASSETCHAINS_SELFIMPORT ) return Invalid("invalid-gateway-import-coin"); - else if ( UnmarshalBurnTx(burnTx,bindtxid,publishers,txids,burntxid,height,burnvout,rawburntx,destpub,amount)==0 || CheckGATEWAYimport(importTx,burnTx,targetSymbol,rawproof,bindtxid,publishers,txids,burntxid,height,burnvout,rawburntx,destpub,amount) < 0 ) + else if ( UnmarshalBurnTx(burnTx,bindtxid,publishers,txids,burntxid,height,burnvout,rawburntx,destpub,amount)==0 || CheckGATEWAYimport(importTx,burnTx,targetSymbol,rawproof,bindtxid,publishers,txids,burntxid,height,burnvout,rawburntx,destpub,amount) < 0 ) return Invalid("GATEWAY-import-failure"); } } diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 21cee8ca1..d76a9c6a9 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -14,6 +14,8 @@ ******************************************************************************/ #include "CCPegs.h" +#include "../importcoin.h" +#include "key_io.h" /* pegs CC is able to create a coin backed (by any supported coin with gateways CC deposits) and pegged to any synthetic price that is able to be calculated based on prices CC @@ -84,6 +86,197 @@ pegs CC is able to create a coin backed (by any supported coin with gateways CC */ // start of consensus code +#ifndef PEGS_TRSHOLDS +#define PEGS_TRSHOLDS +#define PEGS_ACCOUNT_YELLOW_ZONE 60 +#define PEGS_ACCOUNT_TRESHOLD 90 +#define PEGS_GLOBAL_TRESHOLD 60 +#endif // PEGS_TRSHOLDS +#define CC_MARKER_VALUE 10000 + +extern uint64_t ASSETCHAINS_PEGSCCPARAMS[3]; + +extern uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,uint256 &tokenid,std::string &coin,int64_t &totalsupply,uint256 &oracletxid,uint8_t &M,uint8_t &N,std::vector &gatewaypubkeys,uint8_t &taddr,uint8_t &prefix,uint8_t &prefix2,uint8_t &wiftype); +extern int64_t GetTokenBalance(CPubKey pk, uint256 tokenid); +extern int32_t komodo_currentheight(); + +CScript EncodePegsCreateOpRet(std::vector bindtxids) +{ + CScript opret; uint8_t evalcode = EVAL_PEGS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << bindtxids); + return(opret); +} + +uint8_t DecodePegsCreateOpRet(const CScript &scriptPubKey,std::vector &bindtxids) +{ + std::vector vopret; uint8_t *script,e,f; + + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0] == EVAL_PEGS && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> bindtxids) != 0 ) + { + return(f); + } + return(0); +} + +CScript EncodePegsFundOpRet(uint256 tokenid,uint256 pegstxid,CPubKey srcpub,int64_t amount,std::pair account) +{ + CScript opret; uint8_t evalcode=EVAL_PEGS,funcid='F'; struct CCcontract_info *cp,C; CPubKey pegspk; + std::vector pubkeys; vscript_t vopret; + + cp = CCinit(&C,EVAL_PEGS); + pegspk = GetUnspendable(cp,0); + pubkeys.push_back(srcpub); + pubkeys.push_back(pegspk); + LOGSTREAM("pegscc", CCLOG_DEBUG1, stream << "EncodePegsFundOpRet [" << account.first << "," << account.second << "]" << std::endl); + vopret = E_MARSHAL(ss << evalcode << funcid << pegstxid << srcpub << amount << account); + return(EncodeTokenOpRet(tokenid,pubkeys,make_pair(OPRETID_PEGSDATA, vopret))); +} + +uint8_t DecodePegsFundOpRet(const CScript &scriptPubKey,uint256 &tokenid,uint256 &pegstxid,CPubKey &srcpub,int64_t &amount,std::pair &account) +{ + std::vector> oprets; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; std::vector pubkeys; + + if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys, oprets)!=0 && GetOpretBlob(oprets, OPRETID_PEGSDATA, vOpretExtra) && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) + { + vopret=vOpretExtra; + } + else GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0] == EVAL_PEGS && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> pegstxid; ss >> srcpub; ss >> amount; ss >> account) != 0 ) + { + return(f); + } + return(0); +} + +uint8_t DecodePegsGetOpRet(const CTransaction tx,uint256& pegstxid,uint256 &tokenid,CPubKey &srcpub,int64_t &amount,std::pair &account) +{ + std::vector vopret; uint8_t *script; + ImportProof proof; CTransaction burntx; std::vector payouts; + + GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey, vopret); + + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0] == EVAL_IMPORTCOIN && UnmarshalImportTx(tx,proof,burntx,payouts) && UnmarshalBurnTx(burntx,pegstxid,tokenid,srcpub,amount,account)) + { + return('G'); + } + return(0); +} + +CScript EncodePegsReedemOpRet(uint256 tokenid,uint256 pegstxid,CPubKey srcpub,int64_t amount,std::pair account) +{ + CScript opret; uint8_t evalcode=EVAL_PEGS,funcid='R'; struct CCcontract_info *cp,C; + std::vector pubkeys; vscript_t vopret; + + cp = CCinit(&C,EVAL_PEGS); + pubkeys.push_back(srcpub); + vopret = E_MARSHAL(ss << evalcode << funcid << pegstxid << srcpub << amount << account); + return(EncodeTokenOpRet(tokenid,pubkeys,make_pair(OPRETID_PEGSDATA, vopret))); +} + +uint8_t DecodePegsRedeemOpRet(const CScript &scriptPubKey,uint256 &tokenid,uint256 &pegstxid,CPubKey &srcpub,int64_t &amount,std::pair &account) +{ + std::vector> oprets; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; std::vector pubkeys; + + if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys, oprets)!=0 && GetOpretBlob(oprets, OPRETID_PEGSDATA, vOpretExtra) && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) + { + vopret=vOpretExtra; + } + else GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0] == EVAL_PEGS && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> pegstxid; ss >> srcpub; ss >> amount; ss >> account) != 0 ) + { + return(f); + } + return(0); +} + +CScript EncodePegsExchangeOpRet(uint256 tokenid,uint256 pegstxid,CPubKey pk1,CPubKey pk2,int64_t amount,std::pair account) +{ + CScript opret; uint8_t evalcode=EVAL_PEGS,funcid='E'; struct CCcontract_info *cp,C; + std::vector pubkeys; vscript_t vopret; CPubKey pegspk; + + cp = CCinit(&C,EVAL_PEGS); + pegspk = GetUnspendable(cp,0); + pubkeys.push_back(pk1); + pubkeys.push_back(pk2); + vopret = E_MARSHAL(ss << evalcode << funcid << pegstxid << pk1 << amount << account); + return(EncodeTokenOpRet(tokenid,pubkeys,make_pair(OPRETID_PEGSDATA, vopret))); +} + +uint8_t DecodePegsExchangeOpRet(const CScript &scriptPubKey,uint256 &tokenid,uint256 &pegstxid,CPubKey &srcpub,int64_t &amount,std::pair &account) +{ + std::vector> oprets; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; std::vector pubkeys; + + if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys, oprets)!=0 && GetOpretBlob(oprets, OPRETID_PEGSDATA, vOpretExtra) && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) + { + vopret=vOpretExtra; + } + else GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0] == EVAL_PEGS && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> pegstxid; ss >> srcpub; ss >> amount; ss >> account) != 0 ) + { + return(f); + } + return(0); +} + +CScript EncodePegsLiquidateOpRet(uint256 tokenid,uint256 pegstxid,CPubKey srcpub,int64_t amount,std::pair account) +{ + CScript opret; uint8_t evalcode=EVAL_PEGS,funcid='L'; struct CCcontract_info *cp,C; + std::vector pubkeys; vscript_t vopret; + + cp = CCinit(&C,EVAL_PEGS); + pubkeys.push_back(srcpub); + vopret = E_MARSHAL(ss << evalcode << funcid << pegstxid << srcpub << amount << account); + return(EncodeTokenOpRet(tokenid,pubkeys,make_pair(OPRETID_PEGSDATA, vopret))); +} + +uint8_t DecodePegsLiquidateOpRet(const CScript &scriptPubKey,uint256 &tokenid,uint256 &pegstxid,CPubKey &srcpub,int64_t &amount,std::pair &account) +{ + std::vector> oprets; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; std::vector pubkeys; + + if (DecodeTokenOpRet(scriptPubKey,tokenevalcode,tokenid,pubkeys, oprets)!=0 && GetOpretBlob(oprets, OPRETID_PEGSDATA, vOpretExtra) && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) + { + vopret=vOpretExtra; + } + else GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0] == EVAL_PEGS && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> pegstxid; ss >> srcpub; ss >> amount; ss >> account) != 0 ) + { + return(f); + } + return(0); +} + +uint8_t DecodePegsOpRet(CTransaction tx,uint256& pegstxid,uint256& tokenid) +{ + std::vector> oprets; int32_t numvouts=tx.vout.size(); + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; std::vector pubkeys; + ImportProof proof; CTransaction burntx; std::vector payouts; uint256 tmppegstxid; CPubKey srcpub; int64_t amount; std::pair account; + + if (DecodeTokenOpRet(tx.vout[numvouts-1].scriptPubKey,tokenevalcode,tokenid,pubkeys, oprets)!=0 && GetOpretBlob(oprets, OPRETID_PEGSDATA, vOpretExtra) && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) + { + vopret=vOpretExtra; + } + else GetOpReturnData(tx.vout[numvouts-1].scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if (tx.IsPegsImport()) + return(DecodePegsGetOpRet(tx,pegstxid,tokenid,srcpub,amount,account)); + else if ( vopret.size() > 2 && script[0] == EVAL_PEGS) + { + E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> pegstxid); + return(f); + } + return(0); +} int64_t IsPegsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { @@ -137,7 +330,7 @@ bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return eval->Invalid("no validation yet"); + return (true); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); @@ -175,12 +368,14 @@ bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk1,CPubKey pk2,int64_t total,int32_t maxinputs) { // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); + + if (pk2.IsValid()) GetCCaddress1of2(cp,coinaddr,pk1,pk2); + else GetCCaddress(cp,coinaddr,pk1); SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { @@ -189,7 +384,7 @@ int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( (nValue= IsPegsvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) + if (myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -204,76 +399,1005 @@ int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe return(totalinputs); } -std::string PegsGet(uint64_t txfee,int64_t nValue) +int64_t AddPegsTokenInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint256 pegstxid, uint256 tokenid, CPubKey pk1,CPubKey pk2, int64_t total,int32_t maxinputs) { - CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; - cp = CCinit(&C,EVAL_PEGS); - if ( txfee == 0 ) - txfee = 10000; - Pegspk = GetUnspendable(cp,0); - mypk = pubkey2pk(Mypubkey()); - if ( (inputs= AddPegsInputs(cp,mtx,Pegspk,nValue+txfee,60)) > 0 ) + // add threshold check + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + std::vector > unspentOutputs; uint256 tmppegstxid,tmptokenid; CPubKey mypk; + + if (pk2.IsValid()) GetTokensCCaddress1of2(cp,coinaddr,pk1,pk2); + else GetTokensCCaddress(cp,coinaddr,pk1); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( inputs > nValue ) - CCchange = (inputs - nValue - txfee); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,CCchange,Pegspk)); - mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); - j = rand() & 0xfffffff; - for (i=0; i<1000000; i++,j++) + txid = it->first.txhash; + vout = (int32_t)it->first.index; + // no need to prevent dup + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_PEGS << (uint8_t)'G' << j)); - if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) + if (myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 && DecodePegsOpRet(vintx,tmppegstxid,tmptokenid)!=0 && tmppegstxid==pegstxid && tmptokenid==tokenid) { - len >>= 1; - decode_hex(buf,len,(char *)rawhex.c_str()); - hash = bits256_doublesha256(0,buf,len); - if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) - { - fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); - return(rawhex); - } - //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; } } - fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); - return(""); - } else fprintf(stderr,"cant find Pegs inputs\n"); + } + if (pk2.IsValid()) + { + mypk = pubkey2pk(Mypubkey()); + if (mypk!=pk1 && mypk!=pk2) + { + CCaddrTokens1of2set(cp,pk1,pk2,cp->CCpriv,coinaddr); + } + else + { + uint8_t mypriv[32]; + Myprivkey(mypriv); + CCaddrTokens1of2set(cp,pk1,pk2,mypriv,coinaddr); + } + } + return(totalinputs); +} + +std::string PegsDecodeAccountTx(CTransaction tx,CPubKey& pk,int64_t &amount,std::pair &account) +{ + uint256 hashBlock,tokenid,pegstxid; int32_t numvouts=tx.vout.size(); char funcid; + + if ((funcid=DecodePegsOpRet(tx,pegstxid,tokenid))!=0) + { + switch(funcid) + { + case 'F': if (DecodePegsFundOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,pegstxid,pk,amount,account)=='F') return("fund"); + break; + case 'G': if (DecodePegsGetOpRet(tx,pegstxid,tokenid,pk,amount,account)=='G') return("get"); + break; + case 'R': if (DecodePegsRedeemOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,pegstxid,pk,amount,account)=='R') return("redeem"); + break; + case 'E': if (DecodePegsExchangeOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,pegstxid,pk,amount,account)=='R') return("exchange"); + break; + case 'L': if (DecodePegsLiquidateOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,pegstxid,pk,amount,account)=='L') return("liquidate"); + break; + } + } + return (""); +} + +char PegsFindAccount(struct CCcontract_info *cp,CPubKey pk,uint256 pegstxid, uint256 tokenid, uint256 &accounttxid, std::pair &account) +{ + char coinaddr[64]; int64_t nValue,tmpamount; uint256 txid,hashBlock,tmptokenid,tmppegstxid; + CTransaction tx,acctx; int32_t numvouts,vout,ratio; char funcid,f; CPubKey pegspk,tmppk; + std::vector > unspentOutputs; + ImportProof proof; CTransaction burntx; std::vector payouts; + + accounttxid=zeroid; + pegspk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,pk,pegspk); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second.satoshis; + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "txid=" << txid.GetHex() << ", vout=" << vout << ", nValue=" << nValue << std::endl); + if (vout == 1 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && + (f=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid && tokenid==tmptokenid) + { + accounttxid=txid; + funcid=f; + acctx=tx; + } + } + if (accounttxid!=zeroid && myIsutxo_spentinmempool(ignoretxid,ignorevin,accounttxid,1) != 0) + { + accounttxid=zeroid; + BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + { + const CTransaction &txmempool = e.GetTx(); + const uint256 &hash = txmempool.GetHash(); + + if ((numvouts=txmempool.vout.size()) > 0 && (f=DecodePegsOpRet(txmempool,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid && tokenid==tmptokenid) + { + funcid=f; + accounttxid=hash; + acctx=txmempool; + } + } + } + if (accounttxid!=zeroid) + { + PegsDecodeAccountTx(acctx,tmppk,tmpamount,account); + return(funcid); + } + else return(0); +} + +double PegsGetTokenPrice(uint256 tokenid) +{ + int64_t *tokensyn,*btcusd; double price; CTransaction tokentx; uint256 hashBlock; + std::string name,desc; std::vector vorigpubkey; int32_t numvouts; + + if (GetTransaction(tokenid,tokentx,hashBlock,false)!=0 && (numvouts=tokentx.vout.size())>0 && DecodeTokenCreateOpRet(tokentx.vout[numvouts-1].scriptPubKey,vorigpubkey,name,desc)=='c') + { + tokensyn = (int64_t *)calloc(sizeof(*tokensyn) * 3, 1 + PRICES_DAYWINDOW * 2 + PRICES_SMOOTHWIDTH); + btcusd = (int64_t *)calloc(sizeof(*btcusd) * 3, 1 + PRICES_DAYWINDOW * 2 + PRICES_SMOOTHWIDTH); + if (komodo_priceget(tokensyn, komodo_priceind((name+"_BTC").c_str()), komodo_currentheight(), 1) >= 0 && komodo_priceget(btcusd, komodo_priceind("BTC_USD"), komodo_currentheight(), 1) >= 0) + { + price=tokensyn[2]*btcusd[2]; + price=price/COIN/COIN; + return (price); + } + } + return (0); +} + +std::string PegsGetTokenName(uint256 tokenid) +{ + CTransaction tokentx; uint256 hashBlock; std::string name,desc; std::vector vorigpubkey; int32_t numvouts; + + if (GetTransaction(tokenid,tokentx,hashBlock,false)!=0 && (numvouts=tokentx.vout.size())>0 && DecodeTokenCreateOpRet(tokentx.vout[numvouts-1].scriptPubKey,vorigpubkey,name,desc)=='c') + { + return (name); + } + CCerror = strprintf("cant find token create or invalid tokenid %s",tokenid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } -std::string PegsFund(uint64_t txfee,int64_t funds) +double PegsGetAccountRatio(uint256 pegstxid,uint256 tokenid,uint256 accounttxid) +{ + int64_t amount; uint256 hashBlock,tmptokenid,tmppegstxid; + CTransaction tx; int32_t numvouts; char funcid; CPubKey pk; + std::pair account; struct CCcontract_info *cp,C; + + cp = CCinit(&C,EVAL_PEGS); + if (GetTransaction(accounttxid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + (funcid=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid && tokenid==tmptokenid) + { + PegsDecodeAccountTx(tx,pk,amount,account); + return ((double)account.second*100/(account.first*PegsGetTokenPrice(tokenid))); + } + return (0); +} + +double PegsGetGlobalRatio(uint256 pegstxid) +{ + char coinaddr[64]; int64_t nValue,amount,globaldebt=0; uint256 txid,accounttxid,hashBlock,tmppegstxid,tokenid; + CTransaction tx; int32_t numvouts,vout; char funcid; CPubKey mypk,pegspk,pk; + std::vector > unspentOutputs; std::pair account; + std::map> globalaccounts; double globaldeposit=0; + struct CCcontract_info *cp,C; + + cp = CCinit(&C,EVAL_PEGS); + pegspk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,pegspk,pegspk); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second.satoshis; + if (vout == 0 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + (funcid=DecodePegsOpRet(tx,tmppegstxid,tokenid))!=0 && pegstxid==tmppegstxid && (funcid=='F' || funcid=='G' || funcid=='E')) + { + PegsDecodeAccountTx(tx,pk,amount,account); + globalaccounts[tokenid].first+=account.first; + globalaccounts[tokenid].second+=account.second; + } + } + unspentOutputs.clear(); + GetTokensCCaddress(cp,coinaddr,pegspk); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second.satoshis; + if (GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && DecodePegsOpRet(tx,tmppegstxid,tokenid)!=0 && pegstxid==tmppegstxid) + { + globalaccounts[tokenid].first+=nValue; + } + } + for (std::map>::iterator it = globalaccounts.begin(); it != globalaccounts.end(); ++it) + { + globaldeposit+=globalaccounts[it->first].first*PegsGetTokenPrice(it->first); + globaldebt+=globalaccounts[it->first].second; + } + if (globaldebt>0) return ((double)globaldebt*100/globaldeposit); + return (0); +} + +std::string PegsFindBestAccount(struct CCcontract_info *cp,uint256 pegstxid, uint256 tokenid, int64_t tokenamount,uint256 &accounttxid, std::pair &account) +{ + char coinaddr[64]; int64_t nValue,tmpamount; uint256 txid,hashBlock,tmptokenid,tmppegstxid; + CTransaction tx,acctx; int32_t numvouts,vout; char funcid,f; CPubKey pegspk,tmppk; + std::vector > unspentOutputs; + ImportProof proof; CTransaction burntx; std::vector payouts; double ratio,maxratio=0; + std::pair tmpaccount; + + accounttxid=zeroid; + pegspk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,pegspk,pegspk); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second.satoshis; + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "txid=" << txid.GetHex() << ", vout=" << vout << ", nValue=" << nValue << std::endl); + if (vout == 0 && nValue == CC_MARKER_VALUE && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,0) == 0 && + (ratio=PegsGetAccountRatio(pegstxid,tokenid,txid))>(ASSETCHAINS_PEGSCCPARAMS[2]?ASSETCHAINS_PEGSCCPARAMS[2]:PEGS_ACCOUNT_YELLOW_ZONE) && ratio>maxratio) + { + if (myGetTransaction(txid,tx,hashBlock)!=0 && !PegsDecodeAccountTx(tx,tmppk,tmpamount,tmpaccount).empty() && tmpaccount.first>=tokenamount) + { + accounttxid=txid; + acctx=tx; + maxratio=ratio; + } + } + } + if (accounttxid!=zeroid) + { + return(PegsDecodeAccountTx(acctx,tmppk,tmpamount,account)); + } + else return(""); +} + +std::string PegsCreate(uint64_t txfee,int64_t amount, std::vector bindtxids) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Pegspk; CScript opret; struct CCcontract_info *cp,C; + CPubKey mypk,pegspk; struct CCcontract_info *cp,C; CTransaction tx; int32_t numvouts; int64_t totalsupply; std::string coin; + char depositaddr[64]; uint256 txid,hashBlock,tmptokenid,oracletxid; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector pubkeys; + cp = CCinit(&C,EVAL_PEGS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - Pegspk = GetUnspendable(cp,0); - if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) + pegspk = GetUnspendable(cp,0); + for(auto txid : bindtxids) { - mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,funds,Pegspk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); + if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tmptokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype)!='B') + { + CCerror = strprintf("invalid bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } } + if ( AddNormalinputs(mtx,mypk,amount,64) >= amount ) + { + for (int i=0; i<(amount-txfee)/CC_MARKER_VALUE; i++) mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,CC_MARKER_VALUE,pegspk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePegsCreateOpRet(bindtxids))); + } + CCerror = strprintf("error adding normal inputs"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } -UniValue PegsInfo() +std::string PegsFund(uint64_t txfee,uint256 pegstxid, uint256 tokenid,int64_t amount) { - UniValue result(UniValue::VOBJ); char numstr[64]; - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Pegspk; struct CCcontract_info *cp,C; int64_t funding; - result.push_back(Pair("result","success")); - result.push_back(Pair("name","Pegs")); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); std::string coin; + CTransaction pegstx,tx; int32_t numvouts; int64_t totalsupply,balance=0,funds=0,tokenfunds=0; uint256 accounttxid=zeroid,hashBlock,txid,tmptokenid,oracletxid; + CPubKey mypk,pegspk,tmppk; struct CCcontract_info *cp,*cpTokens,CTokens,C; char depositaddr[64],coinaddr[64]; std::pair account(0,0); + uint8_t M,N,taddr,prefix,prefix2,wiftype,mypriv[32]; std::vector pubkeys; bool found=false; std::vector bindtxids; + cp = CCinit(&C,EVAL_PEGS); - Pegspk = GetUnspendable(cp,0); - funding = AddPegsInputs(cp,mtx,Pegspk,0,0); - sprintf(numstr,"%.8f",(double)funding/COIN); - result.push_back(Pair("funding",numstr)); + cpTokens = CCinit(&CTokens,EVAL_TOKENS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + + pegspk = GetUnspendable(cp,0); + if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') + { + CCerror = strprintf("invalid pegstxid ",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + for(auto txid : bindtxids) + { + if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tmptokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype)!='B') + { + CCerror = strprintf("invalid bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (tmptokenid==tokenid) + { + found=true; + break; + } + } + if (!found) + { + CCerror = strprintf("invalid tokenid ",tokenid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if ((balance=GetTokenBalance(mypk,tokenid))>=amount) + { + PegsFindAccount(cp,mypk,pegstxid,tokenid,accounttxid,account); + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "current accounttxid=" << accounttxid.GetHex() << " [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); + if (accounttxid!=zeroid && myIsutxo_spentinmempool(ignoretxid,ignorevin,accounttxid,1) != 0) + { + CCerror = strprintf("previous account tx not yet confirmed"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (accounttxid!=zeroid && (funds=AddPegsInputs(cp,mtx,pegspk,CPubKey(),txfee,1))>=txfee) + { + funds+=2*CC_MARKER_VALUE; + mtx.vin.push_back(CTxIn(accounttxid,0,CScript())); + Myprivkey(mypriv); + mtx.vin.push_back(CTxIn(accounttxid,1,CScript())); + GetCCaddress1of2(cp,coinaddr,mypk,pegspk); + CCaddr1of2set(cp,mypk,pegspk,mypriv,coinaddr); + } + else funds=AddPegsInputs(cp,mtx,pegspk,CPubKey(),txfee+2*CC_MARKER_VALUE,3); + if (funds>=txfee+2*CC_MARKER_VALUE) + { + if ((tokenfunds=AddTokenCCInputs(cpTokens,mtx,mypk,tokenid,amount,64))>=amount) + { + mtx.vout.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,pegspk,pegspk)); + mtx.vout.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,mypk,pegspk)); + mtx.vout.push_back(MakeTokensCC1of2vout(EVAL_PEGS,amount,mypk,pegspk)); + if (tokenfunds-amount>0) mtx.vout.push_back(MakeTokensCC1vout(EVAL_TOKENS,tokenfunds-amount,mypk)); + if (funds>txfee+2*CC_MARKER_VALUE) mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,funds-(txfee+2*CC_MARKER_VALUE),pegspk)); + account.first+=amount; + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "new account [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePegsFundOpRet(tokenid,pegstxid,mypk,amount,account))); + } + } + else + { + CCerror = strprintf("not enough balance in pegs global CC address"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + + } + CCerror = strprintf("not enough balance (%lld) for this amount of tokens %lld",balance,amount); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); +} + +std::string PegsGet(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount) +{ + CMutableTransaction burntx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()),mtx; + CTransaction pegstx,tx; int32_t numvouts; int64_t funds=0; uint256 accounttxid=zeroid,hashBlock,pricestxid; char coinaddr[64]; + CPubKey mypk,pegspk,tmppk; struct CCcontract_info *cp,C; std::pair account(0,0); uint8_t mypriv[32]; + std::vector dummyproof; std::vector vouts; std::vector bindtxids; CScript opret; + + cp = CCinit(&C,EVAL_PEGS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + pegspk = GetUnspendable(cp,0); + if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') + { + CCerror = strprintf("invalid pegstxid ",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (PegsFindAccount(cp,mypk,pegstxid,tokenid,accounttxid,account)==0) + { + CCerror = strprintf("cannot find account from which to issue coins, fund account first with pegsfund!"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (accounttxid!=zeroid && myIsutxo_spentinmempool(ignoretxid,ignorevin,accounttxid,1) != 0) + { + CCerror = strprintf("previous account tx not yet confirmed"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "current accounttxid=" << accounttxid.GetHex() << " [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); + // spending markers + vouts.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,pegspk,pegspk)); + vouts.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,mypk,pegspk)); + // coin issue + vouts.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + account.second+=amount; + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "new account [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); + // burn tx does not exist in pegs method but it must be created in order for import validation to pass + // fictive burntx input of previous account state tx + burntx.vin.push_back(CTxIn(accounttxid,0,CScript())); + // fictive output of coins in burn tx + burntx.vout.push_back(MakeBurnOutput(amount,0xffffffff,"PEGSCC",vouts,dummyproof,pegstxid,tokenid,mypk,amount,account)); + std::vector leaftxids; + BitcoinGetProofMerkleRoot(dummyproof, leaftxids); + MerkleBranch newBranch(0, leaftxids); + TxProof txProof = std::make_pair(burntx.GetHash(), newBranch); + mtx=MakePegsImportCoinTransaction(txProof,burntx,vouts); + Myprivkey(mypriv); + GetCCaddress1of2(cp,coinaddr,mypk,pegspk); + CCaddr1of2set(cp,mypk,pegspk,mypriv,coinaddr); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); +} + +std::string PegsRedeem(uint64_t txfee,uint256 pegstxid, uint256 tokenid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); std::string coin; + CTransaction pegstx,tx; int32_t numvouts; int64_t totalsupply,pegsfunds=0,funds=0,tokenfunds=0,amount; uint256 accounttxid=zeroid,hashBlock,txid,tmptokenid,oracletxid; + CPubKey mypk,pegspk,tmppk; struct CCcontract_info *cp,*cpTokens,CTokens,C; char depositaddr[64],coinaddr[64]; std::pair account(0,0); + uint8_t M,N,taddr,prefix,prefix2,wiftype,mypriv[32]; std::vector pubkeys; bool found=false; std::vector bindtxids; + + cp = CCinit(&C,EVAL_PEGS); + cpTokens = CCinit(&CTokens,EVAL_TOKENS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + pegspk = GetUnspendable(cp,0); + if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') + { + CCerror = strprintf("invalid pegstxid ",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + for(auto txid : bindtxids) + { + if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tmptokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype)!='B') + { + CCerror = strprintf("invalid bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (tmptokenid==tokenid) + { + found=true; + break; + } + } + if (!found) + { + CCerror = strprintf("invalid tokenid ",tokenid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (PegsFindAccount(cp,mypk,pegstxid,tokenid,accounttxid,account)==0) + { + CCerror = strprintf("cannot find account from which to redeem tokens!"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (accounttxid!=zeroid && myIsutxo_spentinmempool(ignoretxid,ignorevin,accounttxid,1) != 0) + { + CCerror = strprintf("previous account tx not yet confirmed"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "current accounttxid=" << accounttxid.GetHex() << " [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); + if ((funds=AddNormalinputs(mtx,mypk,account.second,64))>=account.second ) + { + if (accounttxid!=zeroid && (pegsfunds=AddPegsInputs(cp,mtx,pegspk,CPubKey(),txfee,1))>=txfee) + { + pegsfunds+=2*CC_MARKER_VALUE; + mtx.vin.push_back(CTxIn(accounttxid,0,CScript())); + mtx.vin.push_back(CTxIn(accounttxid,1,CScript())); + Myprivkey(mypriv); + GetCCaddress1of2(cp,coinaddr,mypk,pegspk); + CCaddr1of2set(cp,mypk,pegspk,mypriv,coinaddr); + amount=account.first; + if ((tokenfunds=AddPegsTokenInputs(cp,mtx,pegstxid,tokenid,mypk,pegspk,amount,64))>=amount) + { + if (pegsfunds>=txfee+2*CC_MARKER_VALUE) + { + mtx.vout.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,pegspk,pegspk)); + mtx.vout.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,mypk,pegspk)); + mtx.vout.push_back(MakeTokensCC1vout(EVAL_TOKENS,amount,mypk)); + mtx.vout.push_back(CTxOut(account.second,CScript() << ParseHex(HexStr(CCtxidaddr(coinaddr,pegstxid))) << OP_CHECKSIG)); + if (pegsfunds>txfee+2*CC_MARKER_VALUE) mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,pegsfunds-(txfee+2*CC_MARKER_VALUE),pegspk)); + account.first=0; + account.second=0; + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "new account [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePegsReedemOpRet(tokenid,pegstxid,mypk,amount,account))); + } + else + { + CCerror = strprintf("not enough balance in pegs global CC address"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + } + CCerror = strprintf("not enough tokens in pegs account (%lld) to redeem this amount of tokens %lld",tokenfunds,account.first); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + else + { + CCerror = strprintf("not enough balance in pegs global CC address"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + } + CCerror = strprintf("to redeem from account and close it you must redeem full debt ammount %lld instead of %lld",account.second,funds); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); +} + + +std::string PegsExchange(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t amount) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); std::string coin; + CTransaction pegstx,tx; int32_t numvouts; int64_t totalsupply,pegsfunds=0,funds=0,tokenfunds=0,tokenamount,tmpamount; uint256 accounttxid=zeroid,hashBlock,txid,tmptokenid,oracletxid; + CPubKey mypk,pegspk,tmppk; struct CCcontract_info *cp,*cpTokens,CTokens,C; char depositaddr[64],coinaddr[64]; std::pair account(0,0); + uint8_t M,N,taddr,prefix,prefix2,wiftype,mypriv[32]; std::vector pubkeys; bool found=false; std::vector bindtxids; + + cp = CCinit(&C,EVAL_PEGS); + cpTokens = CCinit(&CTokens,EVAL_TOKENS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + pegspk = GetUnspendable(cp,0); + if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') + { + CCerror = strprintf("invalid pegstxid ",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + for(auto txid : bindtxids) + { + if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tmptokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype)!='B') + { + CCerror = strprintf("invalid bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (tmptokenid==tokenid) + { + found=true; + break; + } + } + if (!found) + { + CCerror = strprintf("invalid tokenid ",tokenid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (PegsFindAccount(cp,mypk,pegstxid,tokenid,accounttxid,account)!=0) + { + CCerror = strprintf("you have active account, please close account first before exchanging other coins!"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if ((funds=AddNormalinputs(mtx,mypk,amount,64))>=amount ) + { + if ((pegsfunds=AddPegsInputs(cp,mtx,pegspk,CPubKey(),txfee,1))>=txfee) + { + tokenamount=amount/PegsGetTokenPrice(tokenid); + tokenfunds=AddPegsTokenInputs(cp,mtx,pegstxid,tokenid,pegspk,CPubKey(),tokenamount,64); + if (tokenfundsCCpriv,coinaddr); + pegsfunds+=2*CC_MARKER_VALUE; + } + if (tokenfunds>=tokenamount) + { + if (accounttxid!=zeroid) + { + mtx.vout.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,pegspk,pegspk)); + mtx.vout.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,tmppk,pegspk)); + } + if ((accounttxid!=zeroid && pegsfunds>=txfee+2*CC_MARKER_VALUE) || pegsfunds>=txfee) + { + mtx.vout.push_back(MakeTokensCC1vout(EVAL_TOKENS,tokenamount,mypk)); + mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(CCtxidaddr(coinaddr,pegstxid))) << OP_CHECKSIG)); + if (tokenfunds>tokenamount) mtx.vout.push_back(MakeTokensCC1of2vout(EVAL_PEGS,tokenfunds-tokenamount,tmppk,pegspk)); + if (accounttxid!=zeroid) + { + if (pegsfunds>txfee+2*CC_MARKER_VALUE) mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,pegsfunds-(txfee+2*CC_MARKER_VALUE),pegspk)); + account.first=account.first-tokenamount; + account.second=account.second-amount; + } + else if (pegsfunds>txfee) mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,pegsfunds-txfee,pegspk)); + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "modified account [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePegsExchangeOpRet(tokenid,pegstxid,mypk,tmppk,amount,account))); + } + else + { + CCerror = strprintf("not enough balance in pegs global CC address"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + } + CCerror = strprintf("not enough tokens in pegs account (%lld) to exchange to this amount of tokens %lld",tokenfunds,tokenamount); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + else + { + CCerror = strprintf("not enough balance in pegs global CC address"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + } + CCerror = strprintf("not enough funds to exchange %lld coins to tokens - balance %lld",amount,funds); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); +} + +std::string PegsLiquidate(uint64_t txfee,uint256 pegstxid, uint256 tokenid, uint256 liquidatetxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); std::string coin; + CTransaction pegstx,tx; int32_t numvouts; int64_t totalsupply,pegsfunds=0,funds=0,tokenfunds=0,amount,burnamount; + CPubKey mypk,pegspk,tmppk; struct CCcontract_info *cp,*cpTokens,CTokens,C; char depositaddr[64],coinaddr[64]; std::pair account(0,0),myaccount(0,0); + uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector pubkeys; bool found=false; std::vector bindtxids; + uint256 hashBlock,txid,tmptokenid,oracletxid,accounttxid; + + cp = CCinit(&C,EVAL_PEGS); + cpTokens = CCinit(&CTokens,EVAL_TOKENS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + pegspk = GetUnspendable(cp,0); + if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') + { + CCerror = strprintf("invalid pegstxid ",pegstxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + for(auto txid : bindtxids) + { + if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + { + CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tmptokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype)!='B') + { + CCerror = strprintf("invalid bindtxid %s",txid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (tmptokenid==tokenid) + { + found=true; + break; + } + } + if (!found) + { + CCerror = strprintf("invalid tokenid ",tokenid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (PegsFindAccount(cp,mypk,pegstxid,tokenid,accounttxid,myaccount)==0) + { + CCerror = strprintf("cannot find account, you must have an account to liquidate another account!"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (accounttxid!=zeroid && myIsutxo_spentinmempool(ignoretxid,ignorevin,accounttxid,1) != 0) + { + CCerror = strprintf("previous account tx not yet confirmed"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (PegsGetAccountRatio(pegstxid,tokenid,liquidatetxid)<(ASSETCHAINS_PEGSCCPARAMS[0]?ASSETCHAINS_PEGSCCPARAMS[0]:PEGS_ACCOUNT_TRESHOLD) || PegsGetGlobalRatio(pegstxid)<(ASSETCHAINS_PEGSCCPARAMS[1]?ASSETCHAINS_PEGSCCPARAMS[1]:PEGS_GLOBAL_TRESHOLD)) + { + CCerror = strprintf("not able to liquidate account until account ratio > %lu%% and global ratio > %lu%%",(ASSETCHAINS_PEGSCCPARAMS[0]?ASSETCHAINS_PEGSCCPARAMS[0]:PEGS_ACCOUNT_TRESHOLD),(ASSETCHAINS_PEGSCCPARAMS[1]?ASSETCHAINS_PEGSCCPARAMS[1]:PEGS_GLOBAL_TRESHOLD)); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (liquidatetxid!=zeroid && GetTransaction(liquidatetxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0 || PegsDecodeAccountTx(tx,tmppk,amount,account).empty()) + { + CCerror = strprintf("cannot find account to liquidate or invalid tx %s!",liquidatetxid.GetHex()); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + if (liquidatetxid!=zeroid && myIsutxo_spentinmempool(ignoretxid,ignorevin,liquidatetxid,1) != 0) + { + CCerror = strprintf("previous liquidate account tx not yet confirmed"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "current accounttxid=" << accounttxid.GetHex() << " [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); + amount=account.first; + burnamount=account.second*0.9; + if ((funds=AddNormalinputs(mtx,mypk,txfee+account.second,64))>=txfee+burnamount) + { + if (liquidatetxid!=zeroid && (pegsfunds=AddPegsInputs(cp,mtx,pegspk,CPubKey(),txfee,1))>=txfee) + { + pegsfunds+=2*CC_MARKER_VALUE; + mtx.vin.push_back(CTxIn(liquidatetxid,0,CScript())); + mtx.vin.push_back(CTxIn(liquidatetxid,1,CScript())); + GetCCaddress1of2(cp,coinaddr,tmppk,pegspk); + CCaddr1of2set(cp,tmppk,pegspk,cp->CCpriv,coinaddr); + if ((tokenfunds=AddPegsTokenInputs(cp,mtx,pegstxid,tokenid,tmppk,pegspk,amount,64))==amount) + { + if (pegsfunds>=txfee+2*CC_MARKER_VALUE) + { + mtx.vout.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,pegspk,pegspk)); + mtx.vout.push_back(MakeCC1of2vout(EVAL_PEGS,CC_MARKER_VALUE,tmppk,pegspk)); + mtx.vout.push_back(MakeTokensCC1vout(EVAL_TOKENS,(int64_t)(amount*0.95),mypk)); + mtx.vout.push_back(MakeTokensCC1vout(EVAL_PEGS,amount-(int64_t)(amount*0.95),pegspk)); + mtx.vout.push_back(CTxOut(burnamount,CScript() << ParseHex(HexStr(CCtxidaddr(coinaddr,pegstxid))) << OP_CHECKSIG)); + if (pegsfunds>txfee+2*CC_MARKER_VALUE) mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,pegsfunds-(txfee+2*CC_MARKER_VALUE),pegspk)); + account.first=0; + account.second=0; + LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "new account [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePegsLiquidateOpRet(tokenid,pegstxid,mypk,amount,account))); + } + CCerror = strprintf("not enough balance in pegs global CC address"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + CCerror = strprintf("tokens amount in pegs account (%lld) not matching amount in account %lld",tokenfunds,account.first); // this shouldn't happen + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + CCerror = strprintf("not enough balance in pegs global CC address"); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } + CCerror = strprintf("not enough funds to liquidate account, you must liquidate full debt ammount %lld instead of %lld",txfee+account.second,funds); + LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + return(""); +} + +UniValue PegsAccountHistory(uint256 pegstxid) +{ + char coinaddr[64]; int64_t nValue,amount; uint256 txid,accounttxid,hashBlock,tmptokenid,tmppegstxid; + CTransaction tx; int32_t numvouts,vout; char funcid; CPubKey mypk,pegspk,pk; std::map> accounts; + std::vector > txids; std::pair account; + UniValue result(UniValue::VOBJ),acc(UniValue::VARR); struct CCcontract_info *cp,C; + + result.push_back(Pair("result","success")); + result.push_back(Pair("name","pegsaccounthistory")); + cp = CCinit(&C,EVAL_PEGS); + mypk = pubkey2pk(Mypubkey()); + pegspk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,mypk,pegspk); + SetCCtxids(txids,coinaddr,true); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second; + if (vout == 1 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + (funcid=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid) + { + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("action",PegsDecodeAccountTx(tx,pk,amount,account))); + obj.push_back(Pair("amount",amount)); + obj.push_back(Pair("accounttxid",txid.GetHex())); + obj.push_back(Pair("token",PegsGetTokenName(tmptokenid))); + obj.push_back(Pair("deposit",account.first)); + obj.push_back(Pair("debt",account.second)); + acc.push_back(obj); + } + } + result.push_back(Pair("account history",acc)); return(result); } +UniValue PegsAccountInfo(uint256 pegstxid) +{ + char coinaddr[64]; int64_t nValue,amount; uint256 txid,accounttxid,hashBlock,tmptokenid,tmppegstxid; std::map> accounts; + CTransaction tx; int32_t numvouts,vout; char funcid; CPubKey mypk,pegspk,pk; + std::vector > unspentOutputs; std::pair account; + UniValue result(UniValue::VOBJ),acc(UniValue::VARR); struct CCcontract_info *cp,C; + + result.push_back(Pair("result","success")); + result.push_back(Pair("name","pegsaccountinfo")); + cp = CCinit(&C,EVAL_PEGS); + mypk = pubkey2pk(Mypubkey()); + pegspk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,mypk,pegspk); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second.satoshis; + //LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "txid=" << txid.GetHex() << ", vout=" << vout << ", nValue=" << nValue << std::endl); + if (vout == 1 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + (funcid=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid) + { + //LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "txid=" << txid.GetHex() << ", vout=" << vout << ", nValue=" << nValue << ", tokenid=" << tmptokenid.GetHex() << std::endl); + PegsDecodeAccountTx(tx,pk,amount,account); + accounts[tmptokenid].first=account.first; + accounts[tmptokenid].second=account.second; + } + } + for (std::map>::iterator it = accounts.begin(); it != accounts.end(); ++it) + { + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("token",PegsGetTokenName(it->first))); + obj.push_back(Pair("deposit",(double)accounts[it->first].first/COIN)); + obj.push_back(Pair("debt",(double)accounts[it->first].second/COIN)); + if (accounts[it->first].first==0 || accounts[it->first].second==0 || PegsGetTokenPrice(it->first)==0) obj.push_back(Pair("ratio",0)); + else obj.push_back(Pair("ratio",strprintf("%.2f%%",(double)accounts[it->first].second*100/(accounts[it->first].first*PegsGetTokenPrice(it->first))))); + acc.push_back(obj); + } + result.push_back(Pair("account info",acc)); + return(result); +} + +UniValue PegsWorstAccounts(uint256 pegstxid) +{ + char coinaddr[64]; int64_t nValue,amount; uint256 txid,accounttxid,hashBlock,tmppegstxid,tokenid,prev; + CTransaction tx; int32_t numvouts,vout; char funcid; CPubKey mypk,pegspk,pk; double ratio; + std::vector > unspentOutputs; std::pair account; + UniValue result(UniValue::VOBJ),acc(UniValue::VARR); struct CCcontract_info *cp,C; std::multimap map; + + result.push_back(Pair("result","success")); + result.push_back(Pair("name","pegsworstaccounts")); + cp = CCinit(&C,EVAL_PEGS); + mypk = pubkey2pk(Mypubkey()); + pegspk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,pegspk,pegspk); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second.satoshis; + if (vout == 0 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + (funcid=DecodePegsOpRet(tx,tmppegstxid,tokenid))!=0 && pegstxid==tmppegstxid) + { + PegsDecodeAccountTx(tx,pk,amount,account); + if (account.first==0 || account.second==0 || PegsGetTokenPrice(tokenid)==0) ratio=0; + else ratio=(double)account.second*100/(account.first*PegsGetTokenPrice(tokenid)); + if (ratio>80) + { + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("accounttxid",txid.GetHex())); + obj.push_back(Pair("deposit",account.first)); + obj.push_back(Pair("debt",account.second)); + obj.push_back(Pair("ratio",strprintf("%.2f%%",ratio))); + map.insert(std::pair(tokenid,obj)); + } + } + } + std::multimap::iterator it = map.begin(); + for (prev=it->first; it != map.end(); ++it) + { + if (it->first!=prev) + { + result.push_back(Pair(PegsGetTokenName(prev),acc)); + acc.clear(); + prev=it->first; + } + acc.push_back(it->second); + } + result.push_back(Pair(PegsGetTokenName(prev),acc)); + return(result); +} + +UniValue PegsInfo(uint256 pegstxid) +{ + char coinaddr[64]; int64_t nValue,amount; uint256 txid,accounttxid,hashBlock,tmppegstxid,tokenid; + CTransaction tx; int32_t numvouts,vout; char funcid; CPubKey mypk,pegspk,pk; + std::vector > unspentOutputs; std::pair account; + std::map> globalaccounts; double globaldeposit=0; + UniValue result(UniValue::VOBJ),acc(UniValue::VARR); struct CCcontract_info *cp,C; + + result.push_back(Pair("result","success")); + result.push_back(Pair("name","pegsinfo")); + cp = CCinit(&C,EVAL_PEGS); + mypk = pubkey2pk(Mypubkey()); + pegspk = GetUnspendable(cp,0); + GetCCaddress1of2(cp,coinaddr,pegspk,pegspk); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second.satoshis; + if (vout == 0 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + (funcid=DecodePegsOpRet(tx,tmppegstxid,tokenid))!=0 && pegstxid==tmppegstxid) + { + PegsDecodeAccountTx(tx,pk,amount,account); + globalaccounts[tokenid].first+=account.first; + globalaccounts[tokenid].second+=account.second; + } + } + unspentOutputs.clear(); + GetTokensCCaddress(cp,coinaddr,pegspk); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second.satoshis; + if (GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && DecodePegsOpRet(tx,tmppegstxid,tokenid)!=0 && pegstxid==tmppegstxid) + { + globalaccounts[tokenid].first+=nValue; + } + } + for (std::map>::iterator it = globalaccounts.begin(); it != globalaccounts.end(); ++it) + { + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("token",PegsGetTokenName(it->first))); + obj.push_back(Pair("total deposit",globalaccounts[it->first].first)); + obj.push_back(Pair("total debt",globalaccounts[it->first].second)); + if (globalaccounts[it->first].first==0 || globalaccounts[it->first].second==0 || PegsGetTokenPrice(it->first)==0) obj.push_back(Pair("total ratio",0)); + else obj.push_back(Pair("total ratio",strprintf("%.2f%%",(double)globalaccounts[it->first].second*100/(globalaccounts[it->first].first*PegsGetTokenPrice(it->first))))); + acc.push_back(obj); + } + result.push_back(Pair("info",acc)); + result.push_back(Pair("global ratio",strprintf("%.2f%%",PegsGetGlobalRatio(pegstxid)))); + return(result); +} diff --git a/src/coins.cpp b/src/coins.cpp index f97ba5eee..92206b653 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -604,6 +604,11 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr return 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { + if (tx.IsPegsImport() && i==0) + { + nResult = GetCoinImportValue(tx); + continue; + } value = GetOutputFor(tx.vin[i]).nValue; nResult += value; #ifdef KOMODO_ENABLE_INTEREST @@ -675,6 +680,7 @@ bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const { if (!tx.IsMint()) { for (unsigned int i = 0; i < tx.vin.size(); i++) { + if (tx.IsPegsImport() && i==0) continue; const COutPoint &prevout = tx.vin[i].prevout; const CCoins* coins = AccessCoins(prevout.hash); if (!coins || !coins->IsAvailable(prevout.n)) { @@ -696,7 +702,7 @@ double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight) const // use the maximum priority for all (partially or fully) shielded transactions. // (Note that coinbase transactions cannot contain JoinSplits, or Sapling shielded Spends or Outputs.) - if (tx.vjoinsplit.size() > 0 || tx.vShieldedSpend.size() > 0 || tx.vShieldedOutput.size() > 0 || tx.IsCoinImport()) { + if (tx.vjoinsplit.size() > 0 || tx.vShieldedSpend.size() > 0 || tx.vShieldedOutput.size() > 0 || tx.IsCoinImport() || tx.IsPegsImport()) { return MAX_PRIORITY; } diff --git a/src/importcoin.cpp b/src/importcoin.cpp index 921d9a745..c3da613c8 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -75,6 +75,18 @@ CTransaction MakeImportCoinTransaction(const ImportProof proof, const CTransacti return CTransaction(mtx); } +CTransaction MakePegsImportCoinTransaction(const ImportProof proof, const CTransaction burnTx, const std::vector payouts, uint32_t nExpiryHeightOverride) +{ + CMutableTransaction mtx; uint256 accounttxid,pegstxid,tokenid; CScript opret; CScript scriptSig; + + mtx=MakeImportCoinTransaction(proof,burnTx,payouts); + // for spending markers in import tx - to track account state + accounttxid=burnTx.vin[0].prevout.hash; + mtx.vin.push_back(CTxIn(accounttxid,0,CScript())); + mtx.vin.push_back(CTxIn(accounttxid,1,CScript())); + return (mtx); +} + CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, const std::string targetSymbol, const std::vector payouts, const std::vector rawproof) { @@ -123,13 +135,30 @@ CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymb return CTxOut(value, CScript() << OP_RETURN << opret); } +CTxOut MakeBurnOutput(CAmount value,uint32_t targetCCid,std::string targetSymbol,const std::vector payouts,std::vector rawproof,uint256 pegstxid, + uint256 tokenid,CPubKey srcpub,int64_t amount,std::pair account) +{ + std::vector opret; + opret = E_MARSHAL(ss << (uint8_t)EVAL_IMPORTCOIN; + ss << VARINT(targetCCid); + ss << targetSymbol; + ss << SerializeHash(payouts); + ss << rawproof; + ss << pegstxid; + ss << tokenid; + ss << srcpub; + ss << amount; + ss << account); + return CTxOut(value, CScript() << OP_RETURN << opret); +} + bool UnmarshalImportTx(const CTransaction importTx, ImportProof &proof, CTransaction &burnTx, std::vector &payouts) { if (importTx.vout.size() < 1) return false; - if (importTx.vin.size() != 1 || importTx.vin[0].scriptSig != (CScript() << E_MARSHAL(ss << EVAL_IMPORTCOIN))) { + if ((!importTx.IsPegsImport() && importTx.vin.size() != 1) || importTx.vin[0].scriptSig != (CScript() << E_MARSHAL(ss << EVAL_IMPORTCOIN))) { LOGSTREAM("importcoin", CCLOG_INFO, stream << "UnmarshalImportTx() incorrect import tx vin" << std::endl); return false; } @@ -263,17 +292,35 @@ bool UnmarshalBurnTx(const CTransaction burnTx,uint256 &bindtxid,std::vector> amount)); } +bool UnmarshalBurnTx(const CTransaction burnTx,uint256 &pegstxid,uint256 &tokenid,CPubKey &srcpub, int64_t &amount,std::pair &account) +{ + std::vector burnOpret,rawproof; bool isEof=true; + uint32_t targetCCid; uint256 payoutsHash; std::string targetSymbol; + uint8_t evalCode; + + + if (burnTx.vout.size() == 0) return false; + GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret); + return (E_UNMARSHAL(burnOpret, ss >> evalCode; + ss >> VARINT(targetCCid); + ss >> targetSymbol; + ss >> payoutsHash; + ss >> rawproof; + ss >> pegstxid; + ss >> tokenid; + ss >> srcpub; + ss >> amount; + ss >> account)); +} /* * Required by main */ CAmount GetCoinImportValue(const CTransaction &tx) { - ImportProof proof; - CTransaction burnTx; - std::vector payouts; - + ImportProof proof; CTransaction burnTx; std::vector payouts; bool isNewImportTx = false; + if ((isNewImportTx = UnmarshalImportTx(tx, proof, burnTx, payouts))) { if (burnTx.vout.size() > 0) { vscript_t vburnOpret; diff --git a/src/importcoin.h b/src/importcoin.h index e016a7c52..955ead825 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -95,16 +95,20 @@ public: CAmount GetCoinImportValue(const CTransaction &tx); CTransaction MakeImportCoinTransaction(const ImportProof proof, const CTransaction burnTx, const std::vector payouts, uint32_t nExpiryHeightOverride = 0); +CTransaction MakePegsImportCoinTransaction(const ImportProof proof, const CTransaction burnTx, const std::vector payouts, uint32_t nExpiryHeightOverride = 0); CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, const std::string targetSymbol, const std::vector payouts, const std::vector rawproof); CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts,std::vector rawproof, uint256 bindtxid,std::vector publishers,std::vectortxids,uint256 burntxid,int32_t height,int32_t burnvout,std::string rawburntx,CPubKey destpub, int64_t amount); CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts,std::vector rawproof,std::string srcaddr, std::string receipt); +CTxOut MakeBurnOutput(CAmount value,uint32_t targetCCid,std::string targetSymbol,const std::vector payouts,std::vector rawproof,uint256 pegstxid, + uint256 tokenid,CPubKey srcpub,int64_t amount,std::pair account); bool UnmarshalBurnTx(const CTransaction burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash,std::vector &rawproof); bool UnmarshalBurnTx(const CTransaction burnTx, std::string &srcaddr, std::string &receipt); bool UnmarshalBurnTx(const CTransaction burnTx,uint256 &bindtxid,std::vector &publishers,std::vector &txids,uint256& burntxid,int32_t &height,int32_t &burnvout,std::string &rawburntx,CPubKey &destpub, int64_t &amount); +bool UnmarshalBurnTx(const CTransaction burnTx,uint256 &pegstxid,uint256 &tokenid,CPubKey &srcpub,int64_t &amount,std::pair &account); bool UnmarshalImportTx(const CTransaction importTx, ImportProof &proof, CTransaction &burnTx,std::vector &payouts); bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& checker, CValidationState &state); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index d8e292431..12efd9d83 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -74,7 +74,7 @@ uint64_t ASSETCHAINS_TIMELOCKGTE = _ASSETCHAINS_TIMELOCKOFF; uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0,ASSETCHAINS_CBOPRET=0; uint64_t ASSETCHAINS_LASTERA = 1; -uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS]; +uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_PEGSCCPARAMS[3]; uint8_t ASSETCHAINS_CCDISABLES[256]; std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1bf8dfbeb..02bdb07ad 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1692,7 +1692,9 @@ int8_t equihash_params_possible(uint64_t n, uint64_t k) void komodo_args(char *argv0) { - std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512] = {0}; + std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; + FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512] = {0}; CTransaction earlytx; uint256 hashBlock; + IS_KOMODO_NOTARY = GetBoolArg("-notary", false); IS_STAKED_NOTARY = GetArg("-stakednotary", -1); memset(ccenables,0,sizeof(ccenables)); @@ -1785,6 +1787,11 @@ void komodo_args(char *argv0) printf("KOMODO_REWIND %d\n",KOMODO_REWIND); } KOMODO_EARLYTXID = Parseuint256(GetArg("-earlytxid","0").c_str()); + if (KOMODO_EARLYTXID!=zeroid && (tx_height(KOMODO_EARLYTXID)==0 || tx_height(KOMODO_EARLYTXID)>100)) + { + fprintf(stderr,"earlytx can be only in first 100 blocks or does not exist\n"); + StartShutdown(); + } ASSETCHAINS_EARLYTXIDCONTRACT = GetArg("-ac_earlytxidcontract",0); if ( name.c_str()[0] != 0 ) { @@ -1937,7 +1944,7 @@ void komodo_args(char *argv0) } }*/ } - if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) + if ( ASSETCHAINS_BEAMPORT != 0 ) { fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n"); StartShutdown(); @@ -1951,18 +1958,33 @@ void komodo_args(char *argv0) StartShutdown(); } } - else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 ) + else if ( ASSETCHAINS_SELFIMPORT == "BEAM" ) { - fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); - StartShutdown(); + if (ASSETCHAINS_BEAMPORT == 0) + { + fprintf(stderr,"missing -ac_beam for BEAM rpcport\n"); + StartShutdown(); + } } - else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 ) + else if ( ASSETCHAINS_SELFIMPORT == "CODA" ) { - fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); - StartShutdown(); + if (ASSETCHAINS_CODAPORT == 0) + { + fprintf(stderr,"missing -ac_coda for CODA rpcport\n"); + StartShutdown(); + } + } + else if ( ASSETCHAINS_SELFIMPORT == "PEGSCC") + { + Split(GetArg("-ac_pegsccparams",""), ASSETCHAINS_PEGSCCPARAMS, 0); + if (ASSETCHAINS_ENDSUBSIDY[0]!=1 || ASSETCHAINS_COMMISSION!=0) + { + fprintf(stderr,"when using import for pegsCC these must be set: -ac_end=1 -ac_perc=0\n"); + StartShutdown(); + } } // else it can be gateway coin - else if (!ASSETCHAINS_SELFIMPORT.empty() && (ASSETCHAINS_ENDSUBSIDY[0]!=1 || ASSETCHAINS_SUPPLY>10 || ASSETCHAINS_COMMISSION!=0)) + else if (!ASSETCHAINS_SELFIMPORT.empty() && (ASSETCHAINS_ENDSUBSIDY[0]!=1 || ASSETCHAINS_SUPPLY>0 || ASSETCHAINS_COMMISSION!=0)) { fprintf(stderr,"when using gateway import these must be set: -ac_end=1 -ac_supply=0 -ac_perc=0\n"); StartShutdown(); diff --git a/src/main.cpp b/src/main.cpp index e01cba61f..ba18fc0e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -735,6 +735,7 @@ bool komodo_dailysnapshot(int32_t height) for (unsigned int j = tx.vin.size(); j-- > 0;) { uint256 blockhash; CTransaction txin; + if (tx.IsPegsImport() && j==0) continue; if ( !tx.IsCoinImport() && !tx.IsCoinBase() && myGetTransaction(tx.vin[j].prevout.hash,txin,blockhash) ) { int vout = tx.vin[j].prevout.n; @@ -1012,6 +1013,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, for (unsigned int i = 0; i < tx.vin.size(); i++) { + if (tx.IsPegsImport() && i==0) continue; const CTxOut& prev = mapInputs.GetOutputFor(tx.vin[i]); vector > vSolutions; @@ -1089,6 +1091,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in unsigned int nSigOps = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { + if (tx.IsPegsImport() && i==0) continue; const CTxOut &prevout = inputs.GetOutputFor(tx.vin[i]); if (prevout.scriptPubKey.IsPayToScriptHash()) nSigOps += prevout.scriptPubKey.GetSigOpCount(tx.vin[i].scriptSig); @@ -1873,7 +1876,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return state.Invalid(false, REJECT_DUPLICATE, "already have coins"); } - if (tx.IsCoinImport()) + if (tx.IsCoinImport() || tx.IsPegsImport()) { // Inverse of normal case; if input exists, it's been spent if (ExistsImportTombstone(tx, view)) @@ -1945,7 +1948,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Keep track of transactions that spend a coinbase, which we re-scan // during reorgs to ensure COINBASE_MATURITY is still met. bool fSpendsCoinbase = false; - if (!fSkipExpiry && !tx.IsCoinImport()) { + if (!fSkipExpiry && !tx.IsCoinImport() && !tx.IsPegsImport()) { BOOST_FOREACH(const CTxIn &txin, tx.vin) { const CCoins *coins = view.AccessCoins(txin.prevout.hash); if (coins->IsCoinBase()) { @@ -1985,7 +1988,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Continuously rate-limit free (really, very-low-fee) transactions // This mitigates 'penny-flooding' -- sending thousands of free transactions just to // be annoying or make others' transactions take longer to confirm. - if (fLimitFree && nFees < ::minRelayTxFee.GetFee(nSize) && !tx.IsCoinImport()) + if (fLimitFree && nFees < ::minRelayTxFee.GetFee(nSize) && !tx.IsCoinImport() && !tx.IsPegsImport()) { static CCriticalSection csFreeLimiter; static double dFreeCount; @@ -2008,7 +2011,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa dFreeCount += nSize; } - if (!tx.IsCoinImport() && fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000 && nFees > nValueOut/19) + if (!tx.IsCoinImport() && !tx.IsPegsImport() && fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000 && nFees > nValueOut/19) { string errmsg = strprintf("absurdly high fees %s, %d > %d", hash.ToString(), @@ -2689,6 +2692,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund { txundo.vprevout.reserve(tx.vin.size()); BOOST_FOREACH(const CTxIn &txin, tx.vin) { + if (tx.IsPegsImport() && txin.prevout.n==10e8) continue; CCoinsModifier coins = inputs.ModifyCoins(txin.prevout.hash); unsigned nPos = txin.prevout.n; @@ -2712,7 +2716,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund inputs.ModifyCoins(tx.GetHash())->FromTx(tx, nHeight); // add outputs // Unorthodox state - if (tx.IsCoinImport()) { + if (tx.IsCoinImport() || tx.IsPegsImport()) { // add a tombstone for the burnTx AddImportTombstone(tx, inputs, nHeight); } @@ -2756,6 +2760,11 @@ namespace Consensus { CAmount nFees = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { + if (tx.IsPegsImport() && i==0) + { + nValueIn=GetCoinImportValue(tx); + continue; + } const COutPoint &prevout = tx.vin[i].prevout; const CCoins *coins = inputs.AccessCoins(prevout.hash); assert(coins); @@ -2867,6 +2876,7 @@ bool ContextualCheckInputs( // still computed and checked, and any change will be caught at the next checkpoint. if (fScriptChecks) { for (unsigned int i = 0; i < tx.vin.size(); i++) { + if (tx.IsPegsImport() && i==0) continue; const COutPoint &prevout = tx.vin[i].prevout; const CCoins* coins = inputs.AccessCoins(prevout.hash); assert(coins); @@ -2902,7 +2912,7 @@ bool ContextualCheckInputs( } } - if (tx.IsCoinImport()) + if (tx.IsCoinImport() || tx.IsPegsImport()) { LOCK(cs_main); ServerTransactionSignatureChecker checker(&tx, 0, 0, false, txdata); @@ -3188,10 +3198,12 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // restore inputs if (!tx.IsMint()) { - const CTxUndo &txundo = blockUndo.vtxundo[i-1]; + CTxUndo &txundo = blockUndo.vtxundo[i-1]; + if (tx.IsPegsImport()) txundo.vprevout.insert(txundo.vprevout.begin(),CTxInUndo()); if (txundo.vprevout.size() != tx.vin.size()) return error("DisconnectBlock(): transaction and undo data inconsistent"); for (unsigned int j = tx.vin.size(); j-- > 0;) { + if (tx.IsPegsImport() && j==0) continue; const COutPoint &out = tx.vin[j].prevout; const CTxInUndo &undo = txundo.vprevout[j]; if (!ApplyTxInUndo(undo, view, out)) @@ -3225,7 +3237,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex } } } - else if (tx.IsCoinImport()) + else if (tx.IsCoinImport() || tx.IsPegsImport()) { RemoveImportTombstone(tx, view); } @@ -3573,6 +3585,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { for (size_t j = 0; j < tx.vin.size(); j++) { + if (tx.IsPegsImport() && j==0) continue; const CTxIn input = tx.vin[j]; const CTxOut &prevout = view.GetOutputFor(tx.vin[j]); diff --git a/src/miner.cpp b/src/miner.cpp index e4e907447..55e2c708f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -323,6 +323,13 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 BOOST_FOREACH(const CTxIn& txin, tx.vin) { + if (tx.IsPegsImport() && txin.prevout.n==10e8) + { + CAmount nValueIn = GetCoinImportValue(tx); // burn amount + nTotalIn += nValueIn; + dPriority += (double)nValueIn * 1000; // flat multiplier... max = 1e16. + continue; + } // Read prev transaction if (!view.HaveCoins(txin.prevout.hash)) { diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index d97ff03fb..0c20908b0 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -46,6 +46,7 @@ #include "zcash/Proof.hpp" extern uint32_t ASSETCHAINS_MAGIC; +extern std::string ASSETCHAINS_SELFIMPORT; // Overwinter transaction version static const int32_t OVERWINTER_TX_VERSION = 3; @@ -711,6 +712,11 @@ public: return (vin.size() == 1 && vin[0].prevout.n == 10e8); } + bool IsPegsImport() const + { + return (ASSETCHAINS_SELFIMPORT=="PEGSCC" && vin[0].prevout.n == 10e8); + } + friend bool operator==(const CTransaction& a, const CTransaction& b) { return a.hash == b.hash; diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 578c2f9ad..f97acf37a 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -206,7 +206,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& UniValue in(UniValue::VOBJ); if (tx.IsCoinBase()) in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); - else if (tx.IsCoinImport()) { + else if (tx.IsCoinImport() && txin.prevout.n==10e8) { in.push_back(Pair("is_import", "1")); ImportProof proof; CTransaction burnTx; std::vector payouts; CTxDestination importaddress; if (UnmarshalImportTx(tx, proof, burnTx, payouts)) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 75360fd35..3aea2d13d 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -554,6 +554,18 @@ static const CRPCCommand vRPCCommands[] = //{ "tokens", "tokenfillswap", &tokenfillswap, true }, { "tokens", "tokenconvert", &tokenconvert, true }, + // pegs + { "pegs", "pegscreate", &pegscreate, true }, + { "pegs", "pegsfund", &pegsfund, true }, + { "pegs", "pegsget", &pegsget, true }, + { "pegs", "pegsredeem", &pegsredeem, true }, + { "pegs", "pegsliquidate", &pegsliquidate, true }, + { "pegs", "pegsexchange", &pegsexchange, true }, + { "pegs", "pegsaccounthistory", &pegsaccounthistory, true }, + { "pegs", "pegsaccountinfo", &pegsaccountinfo, true }, + { "pegs", "pegsworstaccounts", &pegsworstaccounts, true }, + { "pegs", "pegsinfo", &pegsinfo, true }, + /* Address index */ { "addressindex", "getaddressmempool", &getaddressmempool, true }, { "addressindex", "getaddressutxos", &getaddressutxos, false }, diff --git a/src/rpc/server.h b/src/rpc/server.h index d447d2472..0d6543281 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -349,6 +349,16 @@ extern UniValue FSMcreate(const UniValue& params, bool fHelp); extern UniValue FSMlist(const UniValue& params, bool fHelp); extern UniValue FSMinfo(const UniValue& params, bool fHelp); extern UniValue auctionaddress(const UniValue& params, bool fHelp); +extern UniValue pegscreate(const UniValue& params, bool fHelp); +extern UniValue pegsfund(const UniValue& params, bool fHelp); +extern UniValue pegsget(const UniValue& params, bool fHelp); +extern UniValue pegsredeem(const UniValue& params, bool fHelp); +extern UniValue pegsliquidate(const UniValue& params, bool fHelp); +extern UniValue pegsexchange(const UniValue& params, bool fHelp); +extern UniValue pegsaccounthistory(const UniValue& params, bool fHelp); +extern UniValue pegsaccountinfo(const UniValue& params, bool fHelp); +extern UniValue pegsworstaccounts(const UniValue& params, bool fHelp); +extern UniValue pegsinfo(const UniValue& params, bool fHelp); extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp //extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 2b38d7153..5f0fb2a47 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -121,7 +121,10 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, const CTransaction& tx = mapTx.find(hash)->GetTx(); if (!tx.IsCoinImport()) { for (unsigned int i = 0; i < tx.vin.size(); i++) + { + if (tx.IsPegsImport() && i==0) continue; mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i); + } } BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { @@ -147,6 +150,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC uint256 txhash = tx.GetHash(); for (unsigned int j = 0; j < tx.vin.size(); j++) { + if (tx.IsPegsImport() && j==0) continue; const CTxIn input = tx.vin[j]; const CTxOut &prevout = view.GetOutputFor(input); @@ -252,6 +256,7 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac uint256 txhash = tx.GetHash(); for (unsigned int j = 0; j < tx.vin.size(); j++) { + if (tx.IsPegsImport() && j==0) continue; const CTxIn input = tx.vin[j]; const CTxOut &prevout = view.GetOutputFor(input); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ce377d094..d24ec3000 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5336,6 +5336,7 @@ int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits #include "../cc/CCHeir.h" #include "../cc/CCMarmara.h" #include "../cc/CCPayments.h" +#include "../cc/CCPegs.h" int32_t ensure_CCrequirements(uint8_t evalcode) { @@ -7973,8 +7974,206 @@ UniValue heirlist(const UniValue& params, bool fHelp) return (HeirList()); } +UniValue pegscreate(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); int32_t i; std::vector txids; + uint8_t N; std::string hex; uint256 txid; int64_t amount; + + if ( fHelp || params.size()<3) + throw runtime_error("pegscreate amount N bindtxid1 [bindtxid2 ...]\n"); + if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + amount = atof((char *)params[0].get_str().c_str()) * COIN + 0.00000000499999; + N = atoi((char *)params[1].get_str().c_str()); + if ( params.size() < N+1 ) + throw runtime_error("not enough parameters for N gatewaysbind\n"); + for (i=0; i 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt pegscreate"); + return(result); +} + +UniValue pegsfund(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid; int64_t amount; + if ( fHelp || params.size()!=3) + throw runtime_error("pegsfund pegstxid tokenid amount\n"); + if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + pegstxid = Parseuint256(params[0].get_str().c_str()); + tokenid = Parseuint256(params[1].get_str().c_str()); + amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999; + hex = PegsFund(0,pegstxid,tokenid,amount); + RETURN_IF_ERROR(CCerror); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt pegsfund"); + return(result); +} + +UniValue pegsget(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid; int64_t amount; + + if ( fHelp || params.size()!=3) + throw runtime_error("pegsget pegstxid tokenid amount\n"); + if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + pegstxid = Parseuint256(params[0].get_str().c_str()); + tokenid = Parseuint256(params[1].get_str().c_str()); + amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999; + hex = PegsGet(0,pegstxid,tokenid,amount); + RETURN_IF_ERROR(CCerror); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt pegsget"); + return(result); +} + +UniValue pegsredeem(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid; int64_t amount; + + if ( fHelp || params.size()!=2) + throw runtime_error("pegsredem pegstxid tokenid\n"); + if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + pegstxid = Parseuint256(params[0].get_str().c_str()); + tokenid = Parseuint256(params[1].get_str().c_str()); + hex = PegsRedeem(0,pegstxid,tokenid); + RETURN_IF_ERROR(CCerror); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt pegsredeem"); + return(result); +} + +UniValue pegsliquidate(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid,accounttxid; + + if ( fHelp || params.size()!=3) + throw runtime_error("pegsliquidate pegstxid tokenid accounttxid\n"); + if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + pegstxid = Parseuint256(params[0].get_str().c_str()); + tokenid = Parseuint256(params[1].get_str().c_str()); + accounttxid = Parseuint256(params[2].get_str().c_str()); + hex = PegsLiquidate(0,pegstxid,tokenid,accounttxid); + RETURN_IF_ERROR(CCerror); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt pegsliquidate"); + return(result); +} + +UniValue pegsexchange(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; uint256 pegstxid,tokenid,accounttxid; int64_t amount; + + if ( fHelp || params.size()!=3) + throw runtime_error("pegsliquidate pegstxid tokenid accounttxid\n"); + if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + pegstxid = Parseuint256(params[0].get_str().c_str()); + tokenid = Parseuint256(params[1].get_str().c_str()); + amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999; + hex = PegsExchange(0,pegstxid,tokenid,amount); + RETURN_IF_ERROR(CCerror); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt pegsliquidate"); + return(result); +} + +UniValue pegsaccounthistory(const UniValue& params, bool fHelp) +{ + uint256 pegstxid; + + if ( fHelp || params.size() != 1 ) + throw runtime_error("pegsaccounthistory pegstxid\n"); + if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + pegstxid = Parseuint256((char *)params[0].get_str().c_str()); + return(PegsAccountHistory(pegstxid)); +} + +UniValue pegsaccountinfo(const UniValue& params, bool fHelp) +{ + uint256 pegstxid; + + if ( fHelp || params.size() != 1 ) + throw runtime_error("pegsaccountinfo pegstxid\n"); + if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + pegstxid = Parseuint256((char *)params[0].get_str().c_str()); + return(PegsAccountInfo(pegstxid)); +} + +UniValue pegsworstaccounts(const UniValue& params, bool fHelp) +{ + uint256 pegstxid; + + if ( fHelp || params.size() != 1 ) + throw runtime_error("pegsworstaccounts pegstxid\n"); + if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + pegstxid = Parseuint256((char *)params[0].get_str().c_str()); + return(PegsWorstAccounts(pegstxid)); +} + +UniValue pegsinfo(const UniValue& params, bool fHelp) +{ + uint256 pegstxid; + + if ( fHelp || params.size() != 1 ) + throw runtime_error("pegsinfo pegstxid\n"); + if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + pegstxid = Parseuint256((char *)params[0].get_str().c_str()); + return(PegsInfo(pegstxid)); +} extern UniValue dumpprivkey(const UniValue& params, bool fHelp); // in rpcdump.cpp extern UniValue convertpassphrase(const UniValue& params, bool fHelp); From b4b339af72b121da5e8759e96f3ad3236fa09e48 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 22:24:21 -1100 Subject: [PATCH 097/659] Fix NSPV_req --- src/komodo_nSPV.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index ef665a45c..bb54d88ae 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -742,16 +742,17 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) if ( pnode == 0 ) { LOCK(cs_vNodes); - BOOST_FOREACH(CNode *pnode,vNodes) + BOOST_FOREACH(CNode *ptr,vNodes) { - if ( pnode->hSocket == INVALID_SOCKET ) + if ( ptr->hSocket == INVALID_SOCKET ) continue; - if ( (pnode->nServices & mask) == mask && timestamp > pnode->prevtimes[ind] ) + if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) { flag = 1; + pnode = ptr; break; } - else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)pnode->nServices,(long long)mask,timestamp,pnode->prevtimes[ind],ind); + else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); } } else flag = 1; if ( pnode != 0 ) From c7de1dbfec52a6edbc6e33b9d6e86636b468c178 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 4 Jul 2019 11:27:39 +0200 Subject: [PATCH 098/659] Fix --- src/cc/CCtokens.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index c664fd49d..cc073879b 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -401,15 +401,15 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys /*<--not used, always true struct CCcontract_info *cpEvalCode1,CEvalCode1; cpEvalCode1 = CCinit(&CEvalCode1,evalCode1); CPubKey pk=GetUnspendable(cpEvalCode1,0); - testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval1 pegscc cc1of2 pk[0]")) ); - testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval1 pegscc cc1of2 pk[1]")) ); + testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval1 pegscc cc1of2 pk[0] globalccpk")) ); + testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval1 pegscc cc1of2 pk[1] globalccpk")) ); if (evalCode2!=0) { struct CCcontract_info *cpEvalCode2,CEvalCode2; cpEvalCode2 = CCinit(&CEvalCode2,evalCode2); CPubKey pk=GetUnspendable(cpEvalCode2,0); - testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval2 pegscc cc1of2 pk[0]")) ); - testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval2 pegscc cc1of2 pk[1]")) ); + testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval2 pegscc cc1of2 pk[0] globalccpk")) ); + testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval2 pegscc cc1of2 pk[1] globalccpk")) ); } // maybe it is single-eval or dual/three-eval token change? From 1b4f65c45e8ebf4912bfc28b84f42c6ea4c4930f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 22:33:11 -1100 Subject: [PATCH 099/659] Use login address if nspv_listunspent doesn't specify --- src/komodo_nSPV.h | 10 ++++++---- src/wallet/rpcdump.cpp | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index bb54d88ae..16e86e8f1 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -133,6 +133,7 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres ptr->utxos = (struct NSPV_utxoresp *)calloc(sizeof(*ptr->utxos),ptr->numutxos); // relies on uint16_t being "small" to prevent mem exhaustion for (i=0; inumutxos; i++) len += NSPV_rwutxoresp(rwflag,&serialized[len],&ptr->utxos[i]); + fprintf(stderr,"parsed numutxos.%d\n",ptr->numutxos); } len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->total),&ptr->total); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); @@ -820,9 +821,9 @@ UniValue NSPV_utxoresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) item.push_back(Pair("height",(int64_t)utxos[i].height)); item.push_back(Pair("txid",utxos[i].txid.GetHex())); item.push_back(Pair("vout",(int64_t)utxos[i].vout)); - item.push_back(Pair("value",AmountFromValue(utxos[i].satoshis))); + item.push_back(Pair("value",(doublt)utxos[i].satoshis/COIN)); if ( ASSETCHAINS_SYMBOL[0] == 0 ) - item.push_back(Pair("interest",AmountFromValue(utxos[i].extradata))); + item.push_back(Pair("interest",(doublt)utxos[i].extradata/COIN)); array.push_back(item); } return(array); @@ -835,8 +836,9 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) result.push_back(Pair("utxos",NSPV_utxoresp_json(ptr->utxos,ptr->numutxos))); result.push_back(Pair("height",(int64_t)ptr->nodeheight)); result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); - result.push_back(Pair("balance",AmountFromValue(ptr->total))); - result.push_back(Pair("interest",AmountFromValue(ptr->interest))); + result.push_back(Pair("balance",(doublt)ptr->total/COIN)); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + result.push_back(Pair("interest",(doublt)ptr->interest/COIN)); return(result); } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 263145320..830ecc322 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -977,6 +977,7 @@ UniValue NSPV_login(char *wifstr); UniValue NSPV_addressutxos(char *coinaddr); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); uint256 Parseuint256(const char *hexstr); +extern std::string NSPV_address; UniValue nspv_getinfo(const UniValue& params, bool fHelp) { @@ -994,6 +995,8 @@ UniValue nspv_login(const UniValue& params, bool fHelp) UniValue nspv_listunspent(const UniValue& params, bool fHelp) { + if ( params.size() == 0 && NSPV_address.size() != 0 ) + return(NSPV_addressutxos((char *)NSPV_address.c_str())); if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_listunspent address\n"); return(NSPV_addressutxos((char *)params[0].get_str().c_str())); From 259586c017448433ee7676a99694f5313fc46c8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 22:36:50 -1100 Subject: [PATCH 100/659] Double --- src/komodo_nSPV.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 16e86e8f1..9fd7ace1a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -821,9 +821,9 @@ UniValue NSPV_utxoresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) item.push_back(Pair("height",(int64_t)utxos[i].height)); item.push_back(Pair("txid",utxos[i].txid.GetHex())); item.push_back(Pair("vout",(int64_t)utxos[i].vout)); - item.push_back(Pair("value",(doublt)utxos[i].satoshis/COIN)); + item.push_back(Pair("value",(double)utxos[i].satoshis/COIN)); if ( ASSETCHAINS_SYMBOL[0] == 0 ) - item.push_back(Pair("interest",(doublt)utxos[i].extradata/COIN)); + item.push_back(Pair("interest",(double)utxos[i].extradata/COIN)); array.push_back(item); } return(array); @@ -836,9 +836,9 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) result.push_back(Pair("utxos",NSPV_utxoresp_json(ptr->utxos,ptr->numutxos))); result.push_back(Pair("height",(int64_t)ptr->nodeheight)); result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); - result.push_back(Pair("balance",(doublt)ptr->total/COIN)); + result.push_back(Pair("balance",(double)ptr->total/COIN)); if ( ASSETCHAINS_SYMBOL[0] == 0 ) - result.push_back(Pair("interest",(doublt)ptr->interest/COIN)); + result.push_back(Pair("interest",(double)ptr->interest/COIN)); return(result); } From a71f92e8dfbd09706830a396c5d4791f65d3ff14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 22:41:06 -1100 Subject: [PATCH 101/659] data[0] == 188 --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9fd7ace1a..95284f71c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -872,7 +872,7 @@ UniValue NSPV_login(char *wifstr) len = bitcoin_base58decode(data,wifstr); if ( strlen(wifstr) < 64 && (len == 38 && data[len-5] == 1) || (len == 37 && data[len-5] != 1) ) valid = 1; - if ( valid == 0 ) + if ( valid == 0 || data[0] != 188 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid wif")); From d76498c52f940fa9000e7da78883b1e10e132460 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 22:43:05 -1100 Subject: [PATCH 102/659] Force wif prefix --- src/komodo_nSPV.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 95284f71c..18b0ce43e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -871,8 +871,11 @@ UniValue NSPV_login(char *wifstr) UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0; len = bitcoin_base58decode(data,wifstr); if ( strlen(wifstr) < 64 && (len == 38 && data[len-5] == 1) || (len == 37 && data[len-5] != 1) ) + { valid = 1; - if ( valid == 0 || data[0] != 188 ) + data[0] = 188; + } + if ( valid == 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid wif")); From 14caec1083223de4fe1d0af238f6f0442cd13d2c Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 4 Jul 2019 11:39:13 +0200 Subject: [PATCH 103/659] Fix --- src/cc/CCtokens.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index cc073879b..0319af622 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -397,19 +397,19 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys /*<--not used, always true } } - //special check for 3 pubkey tx when spending from 1of2 CC address with on of pubkeys is global CC pubkey + //special check for tx when spending from 1of2 CC address and one of pubkeys is global CC pubkey struct CCcontract_info *cpEvalCode1,CEvalCode1; cpEvalCode1 = CCinit(&CEvalCode1,evalCode1); CPubKey pk=GetUnspendable(cpEvalCode1,0); testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval1 pegscc cc1of2 pk[0] globalccpk")) ); - testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval1 pegscc cc1of2 pk[1] globalccpk")) ); + if (voutPubkeys.size() == 2) testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval1 pegscc cc1of2 pk[1] globalccpk")) ); if (evalCode2!=0) { struct CCcontract_info *cpEvalCode2,CEvalCode2; cpEvalCode2 = CCinit(&CEvalCode2,evalCode2); CPubKey pk=GetUnspendable(cpEvalCode2,0); testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval2 pegscc cc1of2 pk[0] globalccpk")) ); - testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval2 pegscc cc1of2 pk[1] globalccpk")) ); + if (voutPubkeys.size() == 2) testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval2 pegscc cc1of2 pk[1] globalccpk")) ); } // maybe it is single-eval or dual/three-eval token change? From aec5f25b762f9bea24b0570fb41fdb654468803e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 22:45:10 -1100 Subject: [PATCH 104/659] Revert --- src/komodo_nSPV.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 18b0ce43e..bbe3fb1f5 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -871,15 +871,13 @@ UniValue NSPV_login(char *wifstr) UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0; len = bitcoin_base58decode(data,wifstr); if ( strlen(wifstr) < 64 && (len == 38 && data[len-5] == 1) || (len == 37 && data[len-5] != 1) ) - { valid = 1; - data[0] = 188; - } - if ( valid == 0 ) + if ( valid == 0 || data[0] != 188 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid wif")); result.push_back(Pair("len",(int64_t)len)); + result.push_back(Pair("prefix",(int64_t)data[0])); return(result); } memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); From 146ccc202fb0f962a45fcdeca40176bf50bb9d1a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jul 2019 23:12:34 -1100 Subject: [PATCH 105/659] +print --- src/komodo_nSPV.h | 7 +++++-- src/wallet/rpcdump.cpp | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index bbe3fb1f5..3fe3f978e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -583,7 +583,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req ind = (int32_t)(sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes)) - 1; if ( request[0] == NSPV_INFO ) // info { - if ( len == 1 && timestamp > pfrom->prevtimes[ind] + ASSETCHAINS_BLOCKTIME/2 ) + fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); + if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_inforesp I; memset(&I,0,sizeof(I)); @@ -802,7 +803,7 @@ UniValue NSPV_ntz_json(struct NSPV_ntz *ptr) return(result); } -UniValue NSPV_getinfo() +UniValue NSPV_getinfo_json() { UniValue result(UniValue::VOBJ); result.push_back(Pair("result","success")); @@ -940,6 +941,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r switch ( response[0] ) { case NSPV_INFORESP: + NSPV_inforesp_purge(&NSPV_inforesult); NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status break; @@ -958,6 +960,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r fprintf(stderr,"got txproof response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; case NSPV_SPENTINFORESP: + fprintf(stderr,"got spentinfo response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 830ecc322..d6863e88b 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -972,7 +972,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) return EncodeViewingKey(vk); } -UniValue NSPV_getinfo(); +UniValue NSPV_getinfo_json(); UniValue NSPV_login(char *wifstr); UniValue NSPV_addressutxos(char *coinaddr); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); @@ -983,7 +983,7 @@ UniValue nspv_getinfo(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 0 ) throw runtime_error("nspv_getinfo\n"); - return(NSPV_getinfo()); + return(NSPV_getinfo_json()); } UniValue nspv_login(const UniValue& params, bool fHelp) From 591185a0b33bf86ba6f41435afa213490b927616 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 00:29:18 -1100 Subject: [PATCH 106/659] Rest of client side low level rpc, incl messages --- src/komodo_nSPV.h | 161 +++++++++++++++++++++++++++++++++-------- src/rpc/server.cpp | 11 ++- src/rpc/server.h | 3 + src/wallet/rpcdump.cpp | 31 ++++++++ 4 files changed, 172 insertions(+), 34 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3fe3f978e..52d4df060 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -29,8 +29,8 @@ #define NSPV_UTXOSRESP 0x03 #define NSPV_NTZS 0x04 #define NSPV_NTZSRESP 0x05 -#define NSPV_NTZPROOF 0x06 -#define NSPV_NTZPROOFRESP 0x07 +#define NSPV_NTZSPROOF 0x06 +#define NSPV_NTZSPROOFRESP 0x07 #define NSPV_TXPROOF 0x08 #define NSPV_TXPROOFRESP 0x09 #define NSPV_SPENTINFO 0x0a @@ -584,7 +584,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( request[0] == NSPV_INFO ) // info { fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); - if ( timestamp > pfrom->prevtimes[ind] ) + if ( timestamp > pfrom->prevtimes[ind] + ASSETCHAINS_BLOCKTIME/2 ) { struct NSPV_inforesp I; memset(&I,0,sizeof(I)); @@ -647,7 +647,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } } } - else if ( request[0] == NSPV_NTZPROOF ) + else if ( request[0] == NSPV_NTZSPROOF ) { if ( timestamp > pfrom->prevtimes[ind] ) { @@ -662,7 +662,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( (slen= NSPV_getntzsproofresp(&P,prevht,nextht)) > 0 ) { response.resize(1 + slen); - response[0] = NSPV_NTZPROOFRESP; + response[0] = NSPV_NTZSPROOFRESP; if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) { pfrom->PushMessage("nSPV",response); @@ -729,14 +729,17 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req CAmount AmountFromValue(const UniValue& value); int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); -uint32_t NSPV_lastinfo,NSPV_lastutxos,NSPV_logintime; +uint32_t NSPV_lastinfo,NSPV_logintime; char NSPV_wifstr[64]; std::string NSPV_address; -int32_t NSPV_numutxos,NSPV_numspends; struct NSPV_inforesp NSPV_inforesult; struct NSPV_utxosresp NSPV_utxosresult; +struct NSPV_spentinfo NSPV_spentresult; +struct NSPV_ntzsresp NSPV_ntzsresult; +struct NSPV_ntzsproofresp NSPV_ntzsproofresult; +struct NSPV_txproof NSPV_txproofresult; + struct NSPV_utxo *NSPV_utxos; -struct NSPV_spentinfo *NSPV_spends; CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { @@ -778,6 +781,16 @@ void komodo_NSPV_spentinfoclear() NSPV_numspends = 0; } +UniValue NSPV_txproof_json(struct NSPV_txproof *ptr) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("txid",ptr->txid.GetHex())); + result.push_back(Pair("height",(int64_t)ptr->height)); + result.push_back(Pair("txlen",(int64_t)ptr->txlen)); + result.push_back(Pair("txprooflen",(int64_t)ptr->txprooflen)); + return(result); +} + UniValue NSPV_spentinfo_json(struct NSPV_spentinfo *ptr) { UniValue result(UniValue::VOBJ); @@ -843,28 +856,43 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) return(result); } -UniValue NSPV_spentinfo(uint256 txid,int32_t vout) +UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr) { - uint8_t msg[64]; struct NSPV_spentinfo I; int32_t i,len = 0; - for (i=0; iprevntz))); + result.push_back(Pair("next",NSPV_ntz_json(&ptr->nextntz))); + return(result); +} + +UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs) +{ + UniValue array(UniValue::VARR); int32_t i; + for (i=0; i>1) != 0 ) - usleep(250000); - for (i=0; icommon.prevht)); + result.push_back(Pair("nextht",(int64_t)ptr->common.nextht)); + result.push_back(Pair("prevtxid",ptr->prevtxid.GetHex())); + result.push_back(Pair("prevtxidht",(int64_t)ptr->prevtxidht)); + result.push_back(Pair("prevlen",(int64_t)ptr->prevlen)); + result.push_back(Pair("nexttxid",ptr->nexttxid.GetHex())); + result.push_back(Pair("nexttxidht",(int64_t)ptr->nexttxidht)); + result.push_back(Pair("nextlen",(int64_t)ptr->prevlen)); + result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); + result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs))); + return(result); } UniValue NSPV_login(char *wifstr) @@ -913,7 +941,7 @@ UniValue NSPV_addressutxos(char *coinaddr) if ( NSPV_inforesult.height == 0 ) { msg[0] = NSPV_INFO; - NSPV_req(0,msg,1,NODE_NSPV,NSPV_INFO>>1); + NSPV_req(0,msg,1,NODE_NSPV,msg[0]>>1); } slen = (int32_t)strlen(coinaddr); msg[len++] = NSPV_UTXOS; @@ -921,7 +949,7 @@ UniValue NSPV_addressutxos(char *coinaddr) memcpy(&msg[len],coinaddr,slen), len += slen; msg[len] = 0; fprintf(stderr,"issue addressutxos.(%s) (%s)\n",coinaddr,(char *)&msg[2]); - if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,NSPV_UTXOS>>1) != 0 ) + if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) usleep(250000); } if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height ) @@ -933,6 +961,71 @@ UniValue NSPV_addressutxos(char *coinaddr) return(result); } +UniValue NSPV_notarizations(int32_t height) +{ + uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsresp N; + if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) + return(NSPV_ntzs_json(&NSPV_ntzsresult)); + msg[len++] = NSPV_NTZS; + len += iguana_rwnum(1,&msg[len],sizeof(height),&height); + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + usleep(250000); + if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) + return(NSPV_ntzs_json(&NSPV_ntzsresult)); + memset(&N,0,sizeof(N)); + return(NSPV_ntzs_json(&NSPV_ntzsresult)); +} + +UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) +{ + uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsproofresp H; + result.push_back(Pair("prevht",(int64_t)ptr->common.prevht)); + result.push_back(Pair("nextht",(int64_t)ptr->common.nextht)); + if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) + return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); + msg[len++] = NSPV_NTZSPROOF; + len += iguana_rwnum(1,&msg[len],sizeof(prevheight),&prevheight); + len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight); + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + usleep(250000); + if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) + return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); + memset(&H,0,sizeof(H)); + return(NSPV_ntzsproof_json(&NSPV_ntzsresult)); +} + +UniValue NSPV_txproof(uint256 txid,int32_t height) +{ + uint8_t msg[64]; int32_t i,len = 0; struct NSPV_txproof P; + if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) + return(NSPV_txproof_json(&NSPV_txproofresult)); + msg[len++] = NSPV_TXPROOF; + len += iguana_rwnum(1,&msg[len],sizeof(height),&height); + len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + usleep(250000); + if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) + return(NSPV_txproof_json(&NSPV_txproofresult)); + memset(&P,0,sizeof(P)); + return(NSPV_txproof_json(&I)); +} + +UniValue NSPV_spentinfo(uint256 txid,int32_t vout) +{ + uint8_t msg[64]; int32_t i,len = 0; struct NSPV_spentinfo I; + if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) + return(NSPV_spentinfo_json(&NSPV_spentresult)); + msg[len++] = NSPV_SPENTINFO; + len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); + len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); + if ( NSPV_req(0,msg,len,NODE_SPENTINDEX,msg[0]>>1) != 0 ) + usleep(250000); + if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) + return(NSPV_spentinfo_json(&NSPV_spentresult)); + memset(&I,0,sizeof(I)); + return(NSPV_spentinfo_json(&I)); +} + void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response { int32_t len; uint32_t timestamp = (uint32_t)time(NULL); @@ -951,16 +1044,24 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos list break; case NSPV_NTZSRESP: + NSPV_ntzsresp_purge(&NSPV_ntzsresult); + NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); fprintf(stderr,"got ntzs response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; - case NSPV_NTZPROOFRESP: + case NSPV_NTZSPROOFRESP: + NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); + NSPV_rwntzsproofresp(0,&response[1],&NSPV_ntzsproofresult); fprintf(stderr,"got ntzproof response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; case NSPV_TXPROOFRESP: + NSPV_txproof_purge(&NSPV_txproofresult); + NSPV_rwtxproof(0,&response[1],&NSPV_txproofresult); fprintf(stderr,"got txproof response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; case NSPV_SPENTINFORESP: + NSPV_spentinfo_purge(&NSPV_spentresult); + NSPV_rwspentinfo(0,&response[1],&NSPV_spentresult); fprintf(stderr,"got spentinfo response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] break; default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 937ae0632..810848f74 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -417,10 +417,13 @@ static const CRPCCommand vRPCCommands[] = { "FSM", "FSMinfo", &FSMinfo, true }, // fsm - { "nSPV", "nspv_getinfo", &nspv_getinfo, true }, - { "nSPV", "nspv_login", &nspv_login, true }, - { "nSPV", "nspv_listunspent", &nspv_listunspent, true }, - { "nSPV", "nspv_spentinfo", &nspv_spentinfo, true }, + { "nSPV", "nspv_getinfo", &nspv_getinfo, true }, + { "nSPV", "nspv_login", &nspv_login, true }, + { "nSPV", "nspv_listunspent", &nspv_listunspent, true }, + { "nSPV", "nspv_spentinfo", &nspv_spentinfo, true }, + { "nSPV", "nspv_notarizations", &nspv_notarizations, true }, + { "nSPV", "nspv_hdrsproof", &nspv_hdrsproof, true }, + { "nSPV", "nspv_txproof", &nspv_txproof, true }, // rewards { "rewards", "rewardslist", &rewardslist, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index bc895ee53..64c78ea47 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -459,6 +459,9 @@ extern UniValue nspv_getinfo(const UniValue& params, bool fHelp); extern UniValue nspv_login(const UniValue& params, bool fHelp); extern UniValue nspv_listunspent(const UniValue& params, bool fHelp); extern UniValue nspv_spentinfo(const UniValue& params, bool fHelp); +extern UniValue nspv_notarizations(const UniValue& params, bool fHelp); +extern UniValue nspv_hdrsproof(const UniValue& params, bool fHelp); +extern UniValue nspv_txproof(const UniValue& params, bool fHelp); extern UniValue getblocksubsidy(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index d6863e88b..ef779491a 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -976,6 +976,9 @@ UniValue NSPV_getinfo_json(); UniValue NSPV_login(char *wifstr); UniValue NSPV_addressutxos(char *coinaddr); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); +UniValue NSPV_notarizations(int32_t height); +UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight); +UniValue NSPV_txproof(uint256 txid,int32_t vout); uint256 Parseuint256(const char *hexstr); extern std::string NSPV_address; @@ -1012,3 +1015,31 @@ UniValue nspv_spentinfo(const UniValue& params, bool fHelp) return(NSPV_spentinfo(txid,vout)); } +UniValue nspv_notarizations(const UniValue& params, bool fHelp) +{ + int32_t height; + if ( fHelp || params.size() != 1 ) + throw runtime_error("nspv_notarizations height\n"); + height = atoi((char *)params[0].get_str().c_str()); + return(NSPV_notarizations(height)); +} + +UniValue nspv_hdrsproof(const UniValue& params, bool fHelp) +{ + int32_t prevheight,nextheight; + if ( fHelp || params.size() != 2 ) + throw runtime_error("nspv_proof prevheight nextheight\n"); + prevheight = atoi((char *)params[0].get_str().c_str()); + nextheight = atoi((char *)params[0].get_str().c_str()); + return(NSPV_proof(prevheight,nextheight)); +} + +UniValue nspv_txproof(const UniValue& params, bool fHelp) +{ + uint256 txid; int32_t height; + if ( fHelp || params.size() != 2 ) + throw runtime_error("nspv_txproof txid height\n"); + txid = Parseuint256((char *)params[0].get_str().c_str()); + height = atoi((char *)params[1].get_str().c_str()); + return(NSPV_txproof(txid,vout)); +} From aebbaba600543bfaed75cc4be3229f616b33f8c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 00:32:33 -1100 Subject: [PATCH 107/659] Syntax --- src/komodo_nSPV.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 52d4df060..23f69b4a1 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -773,14 +773,6 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) return(0); } -void komodo_NSPV_spentinfoclear() -{ - if ( NSPV_spends != 0 ) - free(NSPV_spends); - NSPV_spends = 0; - NSPV_numspends = 0; -} - UniValue NSPV_txproof_json(struct NSPV_txproof *ptr) { UniValue result(UniValue::VOBJ); @@ -979,8 +971,6 @@ UniValue NSPV_notarizations(int32_t height) UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) { uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsproofresp H; - result.push_back(Pair("prevht",(int64_t)ptr->common.prevht)); - result.push_back(Pair("nextht",(int64_t)ptr->common.nextht)); if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); msg[len++] = NSPV_NTZSPROOF; From 2d47ff5f5c72509a4d07fe6bf3f6fcaf6ed904c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 00:37:22 -1100 Subject: [PATCH 108/659] Syntax --- src/komodo_nSPV.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 23f69b4a1..c07a16003 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -965,7 +965,7 @@ UniValue NSPV_notarizations(int32_t height) if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) return(NSPV_ntzs_json(&NSPV_ntzsresult)); memset(&N,0,sizeof(N)); - return(NSPV_ntzs_json(&NSPV_ntzsresult)); + return(NSPV_ntzs_json(&N)); } UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) @@ -981,7 +981,7 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); memset(&H,0,sizeof(H)); - return(NSPV_ntzsproof_json(&NSPV_ntzsresult)); + return(NSPV_ntzsproof_json(&H)); } UniValue NSPV_txproof(uint256 txid,int32_t height) @@ -997,7 +997,7 @@ UniValue NSPV_txproof(uint256 txid,int32_t height) if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) return(NSPV_txproof_json(&NSPV_txproofresult)); memset(&P,0,sizeof(P)); - return(NSPV_txproof_json(&I)); + return(NSPV_txproof_json(&P)); } UniValue NSPV_spentinfo(uint256 txid,int32_t vout) From c7623db751390f32bf54ea8e17cc742e44c90cf4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 00:42:49 -1100 Subject: [PATCH 109/659] Syntax --- src/komodo_nSPV.h | 58 +++++++++++++++++++++++++++++------------- src/wallet/rpcdump.cpp | 4 +-- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c07a16003..8c4432717 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -942,11 +942,15 @@ UniValue NSPV_addressutxos(char *coinaddr) msg[len] = 0; fprintf(stderr,"issue addressutxos.(%s) (%s)\n",coinaddr,(char *)&msg[2]); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) - usleep(250000); - } - if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height ) - { - return(NSPV_utxosresp_json(&NSPV_utxosresult)); + { + for (i=0; i<10; i++) + { + usleep(100000); + if ( NSPV_inforesult.height != 0 + && NSPV_utxosresult.nodeheight >= NSPV_inforesult.height ) + return(NSPV_utxosresp_json(&NSPV_utxosresult)); + } + } } result.push_back(Pair("result","error")); result.push_back(Pair("error","no utxos result")); @@ -961,9 +965,14 @@ UniValue NSPV_notarizations(int32_t height) msg[len++] = NSPV_NTZS; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) - usleep(250000); - if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) - return(NSPV_ntzs_json(&NSPV_ntzsresult)); + { + for (i=0; i<10; i++) + { + usleep(100000); + if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) + return(NSPV_ntzs_json(&NSPV_ntzsresult)); + } + } memset(&N,0,sizeof(N)); return(NSPV_ntzs_json(&N)); } @@ -977,9 +986,14 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) len += iguana_rwnum(1,&msg[len],sizeof(prevheight),&prevheight); len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) - usleep(250000); - if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) - return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); + { + for (i=0; i<10; i++) + { + usleep(100000); + if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) + return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); + } + } memset(&H,0,sizeof(H)); return(NSPV_ntzsproof_json(&H)); } @@ -993,9 +1007,14 @@ UniValue NSPV_txproof(uint256 txid,int32_t height) len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) - usleep(250000); - if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) - return(NSPV_txproof_json(&NSPV_txproofresult)); + { + for (i=0; i<10; i++) + { + usleep(100000); + if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) + return(NSPV_txproof_json(&NSPV_txproofresult)); + } + } memset(&P,0,sizeof(P)); return(NSPV_txproof_json(&P)); } @@ -1009,9 +1028,14 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); if ( NSPV_req(0,msg,len,NODE_SPENTINDEX,msg[0]>>1) != 0 ) - usleep(250000); - if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) - return(NSPV_spentinfo_json(&NSPV_spentresult)); + { + for (i=0; i<10; i++) + { + usleep(100000); + if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) + return(NSPV_spentinfo_json(&NSPV_spentresult)); + } + } memset(&I,0,sizeof(I)); return(NSPV_spentinfo_json(&I)); } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index ef779491a..3b1fadbf7 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1031,7 +1031,7 @@ UniValue nspv_hdrsproof(const UniValue& params, bool fHelp) throw runtime_error("nspv_proof prevheight nextheight\n"); prevheight = atoi((char *)params[0].get_str().c_str()); nextheight = atoi((char *)params[0].get_str().c_str()); - return(NSPV_proof(prevheight,nextheight)); + return(NSPV_hdrsproof(prevheight,nextheight)); } UniValue nspv_txproof(const UniValue& params, bool fHelp) @@ -1041,5 +1041,5 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp) throw runtime_error("nspv_txproof txid height\n"); txid = Parseuint256((char *)params[0].get_str().c_str()); height = atoi((char *)params[1].get_str().c_str()); - return(NSPV_txproof(txid,vout)); + return(NSPV_txproof(txid,height)); } From e3b27c583ddf2bf7774ee7e3279c858288566713 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 00:47:14 -1100 Subject: [PATCH 110/659] Syntax --- src/komodo_nSPV.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 8c4432717..b9ee8897d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -921,7 +921,7 @@ UniValue NSPV_login(char *wifstr) UniValue NSPV_addressutxos(char *coinaddr) { - UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t slen,len = 0; + UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,slen,len = 0; if ( bitcoin_base58decode(msg,coinaddr) != 25 ) { result.push_back(Pair("result","error")); @@ -940,7 +940,6 @@ UniValue NSPV_addressutxos(char *coinaddr) msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; msg[len] = 0; - fprintf(stderr,"issue addressutxos.(%s) (%s)\n",coinaddr,(char *)&msg[2]); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { for (i=0; i<10; i++) From 6bae7050c33b98844a2aabc715ec1aaa78cd4b8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 01:13:17 -1100 Subject: [PATCH 111/659] Clear freed ptr --- src/komodo_nSPV.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b9ee8897d..701f144b7 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -535,15 +535,24 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) { int32_t i; uint256 hashBlock; + if ( prevht > nextht || (nextht-prevht) > 1440 ) + { + fprintf(stderr,"illegal prevht.%d nextht.%d\n",prevht,nextht); + return(-1); + } ptr->prevtxidht = prevht; ptr->nexttxidht = nextht; ptr->common.numhdrs = (nextht - prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); + fprintf(stderr,"allocate numhdrs.%d\n",ptr->common.numhdrs); for (i=0; icommon.numhdrs; i++) { + fprintf(stderr,"%d ht.%d\n",i,prevht+i); if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) { + fprintf(stderr,"error setting hdr.%d\n",prevht+i); free(ptr->common.hdrs); + ptr->common.hdrs = 0; return(-1); } } From 7958b7ecfc7263692d93f21c1f3fb11640900aa9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 01:32:35 -1100 Subject: [PATCH 112/659] Test --- src/komodo_nSPV.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 701f144b7..522adbcfa 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -76,10 +76,14 @@ int32_t iguana_rwequihdrvec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsize len += iguana_rwnum(rwflag,&serialized[len],sizeof(*vecsizep),vecsizep); if ( (vsize= *vecsizep) != 0 ) { + fprintf(stderr,"vsize.%d ptrp.%p alloc %ld\n",*ptrp,sizeof(struct NSPV_equihdr)*vsize); if ( *ptrp == 0 ) - *ptrp = (struct NSPV_equihdr *)calloc(sizeof(**ptrp),vsize); // relies on uint16_t being "small" to prevent mem exhaustion + *ptrp = (struct NSPV_equihdr *)calloc(sizeof(struct NSPV_equihdr),vsize); // relies on uint16_t being "small" to prevent mem exhaustion for (i=0; ipad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevtxidht),&ptr->prevtxidht); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nexttxidht),&ptr->nexttxidht); + fprintf(stderr,"rwvecgtors lens %d %d\n",ptr->prevlen,ptr->nextlen); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->prevlen,&ptr->prevntz); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->nextlen,&ptr->nextntz); + fprintf(stderr,"rwntzsproof len %d\n",len); return(len); } @@ -544,7 +550,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 ptr->nexttxidht = nextht; ptr->common.numhdrs = (nextht - prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); - fprintf(stderr,"allocate numhdrs.%d\n",ptr->common.numhdrs); + fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); for (i=0; icommon.numhdrs; i++) { fprintf(stderr,"%d ht.%d\n",i,prevht+i); @@ -670,13 +676,16 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&P,0,sizeof(P)); if ( (slen= NSPV_getntzsproofresp(&P,prevht,nextht)) > 0 ) { + fprintf(stderr,"ntzsproof slen.%d\n",slen); response.resize(1 + slen); response[0] = NSPV_NTZSPROOFRESP; if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) { + fprintf(stderr,"respond with %d\n",slen); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } + fprintf(stderr,"purge.%d\n",P.common.numhdrs); NSPV_ntzsproofresp_purge(&P); } } From eadeedff7c59f07b9651b9edaa9bcf59d3eef10e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 01:41:15 -1100 Subject: [PATCH 113/659] Test --- src/komodo_nSPV.h | 4 +++- src/wallet/rpcdump.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 522adbcfa..005d9f330 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -76,7 +76,7 @@ int32_t iguana_rwequihdrvec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsize len += iguana_rwnum(rwflag,&serialized[len],sizeof(*vecsizep),vecsizep); if ( (vsize= *vecsizep) != 0 ) { - fprintf(stderr,"vsize.%d ptrp.%p alloc %ld\n",*ptrp,sizeof(struct NSPV_equihdr)*vsize); + fprintf(stderr,"vsize.%d ptrp.%p alloc %ld\n",vsize,*ptrp,sizeof(struct NSPV_equihdr)*vsize); if ( *ptrp == 0 ) *ptrp = (struct NSPV_equihdr *)calloc(sizeof(struct NSPV_equihdr),vsize); // relies on uint16_t being "small" to prevent mem exhaustion for (i=0; inBits = pindex->nBits; hdr->nNonce = pindex->nNonce; memcpy(hdr->nSolution,&pindex->nSolution[0],sizeof(hdr->nSolution)); + printf("set equihdr size.%d\n",(int32_t)sizeof(*hdr)); return(sizeof(*hdr)); } return(-1); @@ -566,6 +567,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevlen,ptr->prevtxid); ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nextlen,ptr->nexttxid); + fprintf(stderr,"prevlen.%d nextlen.%d size %ld -> %ld\n",ptr->prevlen,ptr->nextlen,sizeof(*ptr),sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); return(sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 3b1fadbf7..256a100f2 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1030,7 +1030,7 @@ UniValue nspv_hdrsproof(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_proof prevheight nextheight\n"); prevheight = atoi((char *)params[0].get_str().c_str()); - nextheight = atoi((char *)params[0].get_str().c_str()); + nextheight = atoi((char *)params[1].get_str().c_str()); return(NSPV_hdrsproof(prevheight,nextheight)); } From 9474454175be35067be9bc76b73ab2085301f599 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 01:43:25 -1100 Subject: [PATCH 114/659] Set numbers --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 005d9f330..66430b01e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -681,6 +681,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req fprintf(stderr,"ntzsproof slen.%d\n",slen); response.resize(1 + slen); response[0] = NSPV_NTZSPROOFRESP; + P.common.numhdrs = (nextht - prevht + 1); if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) { fprintf(stderr,"respond with %d\n",slen); From 7b73eac2c85d0ad003511a579d883f5ee0b91884 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:00:49 -1100 Subject: [PATCH 115/659] Test --- src/komodo_nSPV.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 66430b01e..4604b7bfe 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -568,7 +568,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nextlen,ptr->nexttxid); fprintf(stderr,"prevlen.%d nextlen.%d size %ld -> %ld\n",ptr->prevlen,ptr->nextlen,sizeof(*ptr),sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); - return(sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); + return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); } int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) @@ -671,6 +671,12 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req struct NSPV_ntzsproofresp P; int32_t prevht,nextht; if ( len == 1+sizeof(prevht)+sizeof(nextht) ) { + { + int32_t z; + for (z=0; z<9; z++) + fprintf(stderr,"%02x",request[z]); + fprintf(stderr," -> prevht.%d nextht.%d\n",prevht,nextht); + } iguana_rwnum(0,&request[1],sizeof(prevht),&prevht); iguana_rwnum(0,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); if ( prevht != 0 && nextht != 0 && nextht >= prevht ) @@ -1005,6 +1011,13 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) msg[len++] = NSPV_NTZSPROOF; len += iguana_rwnum(1,&msg[len],sizeof(prevheight),&prevheight); len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight); + { + int32_t z; + for (z=0; z<9; z++) + fprintf(stderr,"%02x",msg[z]); + fprintf(stderr," -> prevht.%d nextht.%d\n",prevht,nextht); + } + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i<10; i++) From 729de8bfdcd831c46eeb56e62f48179a24a47e03 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:02:03 -1100 Subject: [PATCH 116/659] Syntax --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4604b7bfe..4272ee2f0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1015,7 +1015,7 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) int32_t z; for (z=0; z<9; z++) fprintf(stderr,"%02x",msg[z]); - fprintf(stderr," -> prevht.%d nextht.%d\n",prevht,nextht); + fprintf(stderr," -> prevht.%d nextht.%d\n",prevheight,nextheight); } if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) From 88eb27ff47bae238b51e9b6bc6ed108e7947f5fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:08:34 -1100 Subject: [PATCH 117/659] Test --- src/komodo_nSPV.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4272ee2f0..dd7b77421 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -671,14 +671,14 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req struct NSPV_ntzsproofresp P; int32_t prevht,nextht; if ( len == 1+sizeof(prevht)+sizeof(nextht) ) { + iguana_rwnum(0,&request[1],sizeof(prevht),&prevht); + iguana_rwnum(0,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); { int32_t z; for (z=0; z<9; z++) fprintf(stderr,"%02x",request[z]); fprintf(stderr," -> prevht.%d nextht.%d\n",prevht,nextht); } - iguana_rwnum(0,&request[1],sizeof(prevht),&prevht); - iguana_rwnum(0,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); if ( prevht != 0 && nextht != 0 && nextht >= prevht ) { memset(&P,0,sizeof(P)); @@ -1012,10 +1012,12 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) len += iguana_rwnum(1,&msg[len],sizeof(prevheight),&prevheight); len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight); { - int32_t z; + int32_t z,prevht,nextht; for (z=0; z<9; z++) fprintf(stderr,"%02x",msg[z]); - fprintf(stderr," -> prevht.%d nextht.%d\n",prevheight,nextheight); + iguana_rwnum(0,&msg[1],sizeof(prevht),&prevht); + iguana_rwnum(0,&msg[5],sizeof(nextht),&nextht); + fprintf(stderr," -> prevht.%d nextht.%d\n",prevht,nextht); } if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) From a514dd239fc5de77b2ab08dd71152627d9a9516b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:17:10 -1100 Subject: [PATCH 118/659] Test --- src/komodo_nSPV.h | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index dd7b77421..4cb0d71b0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -673,28 +673,19 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { iguana_rwnum(0,&request[1],sizeof(prevht),&prevht); iguana_rwnum(0,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); - { - int32_t z; - for (z=0; z<9; z++) - fprintf(stderr,"%02x",request[z]); - fprintf(stderr," -> prevht.%d nextht.%d\n",prevht,nextht); - } if ( prevht != 0 && nextht != 0 && nextht >= prevht ) { memset(&P,0,sizeof(P)); if ( (slen= NSPV_getntzsproofresp(&P,prevht,nextht)) > 0 ) { - fprintf(stderr,"ntzsproof slen.%d\n",slen); response.resize(1 + slen); response[0] = NSPV_NTZSPROOFRESP; P.common.numhdrs = (nextht - prevht + 1); if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) { - fprintf(stderr,"respond with %d\n",slen); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } - fprintf(stderr,"purge.%d\n",P.common.numhdrs); NSPV_ntzsproofresp_purge(&P); } } @@ -1011,22 +1002,16 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) msg[len++] = NSPV_NTZSPROOF; len += iguana_rwnum(1,&msg[len],sizeof(prevheight),&prevheight); len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight); - { - int32_t z,prevht,nextht; - for (z=0; z<9; z++) - fprintf(stderr,"%02x",msg[z]); - iguana_rwnum(0,&msg[1],sizeof(prevht),&prevht); - iguana_rwnum(0,&msg[5],sizeof(nextht),&nextht); - fprintf(stderr," -> prevht.%d nextht.%d\n",prevht,nextht); - } - if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i<10; i++) { usleep(100000); if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) + { + fprintf(stderr,"got ntzsproof\n"); return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); + } } } memset(&H,0,sizeof(H)); @@ -1100,7 +1085,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_NTZSPROOFRESP: NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); NSPV_rwntzsproofresp(0,&response[1],&NSPV_ntzsproofresult); - fprintf(stderr,"got ntzproof response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] + fprintf(stderr,"got ntzproof response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsproofresult.common.prevht,NSPV_ntzsproofresult.common.nextht); // update utxos[i] break; case NSPV_TXPROOFRESP: NSPV_txproof_purge(&NSPV_txproofresult); From 8716c1965253c2796256a765027d3c654b210bef Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:22:16 -1100 Subject: [PATCH 119/659] -print --- src/komodo_nSPV.h | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4cb0d71b0..3d1f00f97 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -76,14 +76,11 @@ int32_t iguana_rwequihdrvec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsize len += iguana_rwnum(rwflag,&serialized[len],sizeof(*vecsizep),vecsizep); if ( (vsize= *vecsizep) != 0 ) { - fprintf(stderr,"vsize.%d ptrp.%p alloc %ld\n",vsize,*ptrp,sizeof(struct NSPV_equihdr)*vsize); + //fprintf(stderr,"vsize.%d ptrp.%p alloc %ld\n",vsize,*ptrp,sizeof(struct NSPV_equihdr)*vsize); if ( *ptrp == 0 ) *ptrp = (struct NSPV_equihdr *)calloc(sizeof(struct NSPV_equihdr),vsize); // relies on uint16_t being "small" to prevent mem exhaustion for (i=0; ipad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevtxidht),&ptr->prevtxidht); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nexttxidht),&ptr->nexttxidht); - fprintf(stderr,"rwvecgtors lens %d %d\n",ptr->prevlen,ptr->nextlen); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->prevlen,&ptr->prevntz); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->nextlen,&ptr->nextntz); - fprintf(stderr,"rwntzsproof len %d\n",len); return(len); } @@ -392,7 +387,6 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check { int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; std::vector > unspentOutputs; - fprintf(stderr,"getaddressutxos for %s\n",coinaddr); SetCCunspents(unspentOutputs,coinaddr,false); maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); @@ -533,7 +527,6 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) hdr->nBits = pindex->nBits; hdr->nNonce = pindex->nNonce; memcpy(hdr->nSolution,&pindex->nSolution[0],sizeof(hdr->nSolution)); - printf("set equihdr size.%d\n",(int32_t)sizeof(*hdr)); return(sizeof(*hdr)); } return(-1); @@ -547,14 +540,13 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 fprintf(stderr,"illegal prevht.%d nextht.%d\n",prevht,nextht); return(-1); } - ptr->prevtxidht = prevht; - ptr->nexttxidht = nextht; + ptr->common.prevht = prevht; + ptr->common.nextht = nextht; ptr->common.numhdrs = (nextht - prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); for (i=0; icommon.numhdrs; i++) { - fprintf(stderr,"%d ht.%d\n",i,prevht+i); if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) { fprintf(stderr,"error setting hdr.%d\n",prevht+i); @@ -567,7 +559,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevlen,ptr->prevtxid); ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nextlen,ptr->nexttxid); - fprintf(stderr,"prevlen.%d nextlen.%d size %ld -> %ld\n",ptr->prevlen,ptr->nextlen,sizeof(*ptr),sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); + //fprintf(stderr,"prevlen.%d nextlen.%d size %ld -> %ld\n",ptr->prevlen,ptr->nextlen,sizeof(*ptr),sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); } @@ -600,7 +592,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req ind = (int32_t)(sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes)) - 1; if ( request[0] == NSPV_INFO ) // info { - fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); + //fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); if ( timestamp > pfrom->prevtimes[ind] + ASSETCHAINS_BLOCKTIME/2 ) { struct NSPV_inforesp I; @@ -628,7 +620,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&U,0,sizeof(U)); if ( (slen= NSPV_getaddressutxos(&U,coinaddr)) > 0 ) { - printf("getaddressutxos.(%s) slen.%d\n",coinaddr,slen); + //printf("getaddressutxos.(%s) slen.%d\n",coinaddr,slen); response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) @@ -774,8 +766,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) flag = 1; pnode = ptr; break; - } - else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); + } // else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); } } else flag = 1; if ( pnode != 0 ) @@ -783,7 +774,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); + //fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; return(pnode); From 68f61aea99eeb8f278f2d3ca400ae60aba892d8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:22:46 -1100 Subject: [PATCH 120/659] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index d30213d6b..f73a3cdd1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7231,7 +7231,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { if ( (pfrom->nServices & NODE_NSPV) == 0 ) { - fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); + //fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); pfrom->fDisconnect = true; return false; } From 14815c3a5ceafb20d32dcfc97892fa3ff65b2bfb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:26:25 -1100 Subject: [PATCH 121/659] array.push_back(item); --- src/komodo_nSPV.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3d1f00f97..c96ef235d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -544,7 +544,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 ptr->common.nextht = nextht; ptr->common.numhdrs = (nextht - prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); - fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); + //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); for (i=0; icommon.numhdrs; i++) { if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) @@ -875,6 +875,7 @@ UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs) item.push_back(Pair("hashPrevBlock",hdrs[i].hashPrevBlock.GetHex())); item.push_back(Pair("hashMerkleRoot",hdrs[i].hashMerkleRoot.GetHex())); item.push_back(Pair("nTime",(int64_t)hdrs[i].nTime)); + array.push_back(item); } return(array); } @@ -999,10 +1000,7 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) { usleep(100000); if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) - { - fprintf(stderr,"got ntzsproof\n"); return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); - } } } memset(&H,0,sizeof(H)); From 40eae4e3822d2a7007e7f50b1c4c856a0f1be09f Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 4 Jul 2019 15:40:10 +0200 Subject: [PATCH 122/659] Fix pegscreate number of vouts --- src/cc/pegs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index d76a9c6a9..2e658fd0a 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -675,7 +675,7 @@ std::string PegsCreate(uint64_t txfee,int64_t amount, std::vector bindt } if ( AddNormalinputs(mtx,mypk,amount,64) >= amount ) { - for (int i=0; i<(amount-txfee)/CC_MARKER_VALUE; i++) mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,CC_MARKER_VALUE,pegspk)); + for (int i=0; i<100; i++) mtx.vout.push_back(MakeCC1vout(EVAL_PEGS,(amount-txfee)/100,pegspk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePegsCreateOpRet(bindtxids))); } CCerror = strprintf("error adding normal inputs"); From c617e6e9597e3d9795dd52c6f2c03a6d2fd24e30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:41:54 -1100 Subject: [PATCH 123/659] Test --- src/komodo_nSPV.h | 22 ++++++++++++++++++---- src/main.cpp | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c96ef235d..56eb951ab 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -227,6 +227,7 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); + fprintf(stderr,"rwtxproof len.%d\n",len); return(len); } @@ -472,8 +473,11 @@ uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) return(0); string strHex = EncodeHexTx(tx); *txlenp = (int32_t)strHex.size() >> 1; - rawtx = (uint8_t *)calloc(1,*txlenp); - decode_hex(rawtx,*txlenp,(char *)strHex.c_str()); + if ( *txlenp > 0 ) + { + rawtx = (uint8_t *)calloc(1,*txlenp); + decode_hex(rawtx,*txlenp,(char *)strHex.c_str()); + } } return(rawtx); } @@ -504,8 +508,12 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) ssMB << mb; std::vector proof(ssMB.begin(), ssMB.end()); ptr->txprooflen = (int32_t)proof.size(); - ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); - memcpy(ptr->txproof,&proof[0],ptr->txprooflen); + if ( ptr->txprooflen > 0 ) + { + ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); + memcpy(ptr->txproof,&proof[0],ptr->txprooflen); + } + fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); } } @@ -693,11 +701,13 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { iguana_rwnum(0,&request[1],sizeof(height),&height); iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); + fprintf(stderr,"got txid ht.%d\n",txid.GetHex().c_str(),height); memset(&P,0,sizeof(P)); if ( (slen= NSPV_gettxproof(&P,txid,height)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_TXPROOFRESP; + fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) { pfrom->PushMessage("nSPV",response); @@ -1015,13 +1025,17 @@ UniValue NSPV_txproof(uint256 txid,int32_t height) msg[len++] = NSPV_TXPROOF; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); + fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i<10; i++) { usleep(100000); if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) + { + fprintf(stderr,"got txproof\n"); return(NSPV_txproof_json(&NSPV_txproofresult)); + } } } memset(&P,0,sizeof(P)); diff --git a/src/main.cpp b/src/main.cpp index f73a3cdd1..27646ec0b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7053,8 +7053,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, const CChainParams& chainparams = Params(); LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); //if ( KOMODO_NSPV != 0 ) - if ( strCommand != "version" && strCommand != "verack" ) - fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); + //if ( strCommand != "version" && strCommand != "verack" ) + // fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); From 1725ce18d5acca7e99154c62747751716c83b622 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:47:13 -1100 Subject: [PATCH 124/659] +print --- src/komodo_nSPV.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 56eb951ab..eba075623 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -227,7 +227,6 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); - fprintf(stderr,"rwtxproof len.%d\n",len); return(len); } @@ -391,6 +390,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check SetCCunspents(unspentOutputs,coinaddr,false); maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); + fprintf(stderr,"getaddressutxos %s\n",coinaddr); if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); @@ -513,7 +513,7 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); memcpy(ptr->txproof,&proof[0],ptr->txprooflen); } - fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); + //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); } } @@ -628,7 +628,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&U,0,sizeof(U)); if ( (slen= NSPV_getaddressutxos(&U,coinaddr)) > 0 ) { - //printf("getaddressutxos.(%s) slen.%d\n",coinaddr,slen); + printf("getaddressutxos.(%s) slen.%d\n",coinaddr,slen); response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) @@ -701,13 +701,12 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { iguana_rwnum(0,&request[1],sizeof(height),&height); iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); - fprintf(stderr,"got txid ht.%d\n",txid.GetHex().c_str(),height); + //fprintf(stderr,"got txid ht.%d\n",txid.GetHex().c_str(),height); memset(&P,0,sizeof(P)); if ( (slen= NSPV_gettxproof(&P,txid,height)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_TXPROOFRESP; - fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) { pfrom->PushMessage("nSPV",response); From a283a80dc118076c0e25f30c64df2a0ca1b404d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 02:51:36 -1100 Subject: [PATCH 125/659] Speed up listunspent --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index eba075623..c14de849b 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -601,7 +601,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( request[0] == NSPV_INFO ) // info { //fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); - if ( timestamp > pfrom->prevtimes[ind] + ASSETCHAINS_BLOCKTIME/2 ) + if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_inforesp I; memset(&I,0,sizeof(I)); @@ -1150,7 +1150,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages } } }*/ - if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + ASSETCHAINS_BLOCKTIME/2 ) + if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) { if ( (rand() % 100) < 10 ) // randomize which peer to query { From 72131969548e13252d435a829b230a8b8c3184cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 03:00:03 -1100 Subject: [PATCH 126/659] +pront --- src/komodo_nSPV.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c14de849b..74d97506e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -134,7 +134,6 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres ptr->utxos = (struct NSPV_utxoresp *)calloc(sizeof(*ptr->utxos),ptr->numutxos); // relies on uint16_t being "small" to prevent mem exhaustion for (i=0; inumutxos; i++) len += NSPV_rwutxoresp(rwflag,&serialized[len],&ptr->utxos[i]); - fprintf(stderr,"parsed numutxos.%d\n",ptr->numutxos); } len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->total),&ptr->total); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); @@ -390,7 +389,6 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check SetCCunspents(unspentOutputs,coinaddr,false); maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); - fprintf(stderr,"getaddressutxos %s\n",coinaddr); if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); @@ -600,7 +598,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req ind = (int32_t)(sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes)) - 1; if ( request[0] == NSPV_INFO ) // info { - //fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); + fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_inforesp I; @@ -609,9 +607,11 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_INFORESP; - NSPV_rwinforesp(1,&response[1],&I); - pfrom->PushMessage("nSPV",response); - pfrom->prevtimes[ind] = timestamp; + if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } NSPV_inforesp_purge(&I); } } @@ -628,7 +628,6 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&U,0,sizeof(U)); if ( (slen= NSPV_getaddressutxos(&U,coinaddr)) > 0 ) { - printf("getaddressutxos.(%s) slen.%d\n",coinaddr,slen); response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) @@ -1152,11 +1151,9 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages }*/ if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) { - if ( (rand() % 100) < 10 ) // randomize which peer to query - { - msg[len++] = NSPV_INFO; - NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); - } + len = 0; + msg[len++] = NSPV_INFO; + NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); } } From f06ac1277fadaa9cb0391879c98ea1e4d6e22a74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 03:08:28 -1100 Subject: [PATCH 127/659] Test --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 74d97506e..69cca2712 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -618,6 +618,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } else if ( request[0] == NSPV_UTXOS ) { + fprintf(stderr,"utxos: %u > %u, ind.%d, len.%d\n",timestamp,pfrom->prevtimes[ind],ind,len); if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_utxosresp U; char coinaddr[64]; From a53d5c6d7ec183a0363c8ec0bf1907105f764cba Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 03:12:51 -1100 Subject: [PATCH 128/659] Skip 0 check --- src/komodo_nSPV.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 69cca2712..f61862622 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -952,6 +952,7 @@ UniValue NSPV_addressutxos(char *coinaddr) if ( NSPV_inforesult.height == 0 ) { msg[0] = NSPV_INFO; + fprintf(stderr,"issue getinfo\n"); NSPV_req(0,msg,1,NODE_NSPV,msg[0]>>1); } slen = (int32_t)strlen(coinaddr); @@ -959,13 +960,13 @@ UniValue NSPV_addressutxos(char *coinaddr) msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; msg[len] = 0; + fprintf(stderr,"issue addrindex\n"); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { for (i=0; i<10; i++) { usleep(100000); - if ( NSPV_inforesult.height != 0 - && NSPV_utxosresult.nodeheight >= NSPV_inforesult.height ) + if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); } } From 74440595f507def9be77ab7dea6db65eee11bdc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 03:15:54 -1100 Subject: [PATCH 129/659] Remove guard --- src/komodo_nSPV.h | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f61862622..4ac396846 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -947,28 +947,25 @@ UniValue NSPV_addressutxos(char *coinaddr) result.push_back(Pair("error","invalid address")); return(result); } - if ( NSPV_inforesult.height == 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) + if ( NSPV_inforesult.height == 0 ) { - if ( NSPV_inforesult.height == 0 ) + msg[0] = NSPV_INFO; + fprintf(stderr,"issue getinfo\n"); + NSPV_req(0,msg,1,NODE_NSPV,msg[0]>>1); + } + slen = (int32_t)strlen(coinaddr); + msg[len++] = NSPV_UTXOS; + msg[len++] = slen; + memcpy(&msg[len],coinaddr,slen), len += slen; + msg[len] = 0; + fprintf(stderr,"issue addrindex\n"); + if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) + { + for (i=0; i<10; i++) { - msg[0] = NSPV_INFO; - fprintf(stderr,"issue getinfo\n"); - NSPV_req(0,msg,1,NODE_NSPV,msg[0]>>1); - } - slen = (int32_t)strlen(coinaddr); - msg[len++] = NSPV_UTXOS; - msg[len++] = slen; - memcpy(&msg[len],coinaddr,slen), len += slen; - msg[len] = 0; - fprintf(stderr,"issue addrindex\n"); - if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) - { - for (i=0; i<10; i++) - { - usleep(100000); - if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height ) - return(NSPV_utxosresp_json(&NSPV_utxosresult)); - } + usleep(100000); + if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height ) + return(NSPV_utxosresp_json(&NSPV_utxosresult)); } } result.push_back(Pair("result","error")); From 33d82c5bb6abcdd5064ae5fbba4a52e8d4ea1e59 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 03:20:07 -1100 Subject: [PATCH 130/659] -print --- src/komodo_nSPV.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4ac396846..e0eb47988 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -598,7 +598,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req ind = (int32_t)(sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes)) - 1; if ( request[0] == NSPV_INFO ) // info { - fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); + //fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_inforesp I; @@ -618,7 +618,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } else if ( request[0] == NSPV_UTXOS ) { - fprintf(stderr,"utxos: %u > %u, ind.%d, len.%d\n",timestamp,pfrom->prevtimes[ind],ind,len); + //fprintf(stderr,"utxos: %u > %u, ind.%d, len.%d\n",timestamp,pfrom->prevtimes[ind],ind,len); if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_utxosresp U; char coinaddr[64]; @@ -958,7 +958,6 @@ UniValue NSPV_addressutxos(char *coinaddr) msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; msg[len] = 0; - fprintf(stderr,"issue addrindex\n"); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { for (i=0; i<10; i++) @@ -1022,17 +1021,14 @@ UniValue NSPV_txproof(uint256 txid,int32_t height) msg[len++] = NSPV_TXPROOF; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); - fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height); + //fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i<10; i++) { usleep(100000); if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) - { - fprintf(stderr,"got txproof\n"); return(NSPV_txproof_json(&NSPV_txproofresult)); - } } } memset(&P,0,sizeof(P)); From 6fec63376ceb575f0ec05adecf9e472eff60e5ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 19:04:02 -1100 Subject: [PATCH 131/659] nspv_hdrsproof --- src/wallet/rpcdump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 256a100f2..f7357aecf 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1028,7 +1028,7 @@ UniValue nspv_hdrsproof(const UniValue& params, bool fHelp) { int32_t prevheight,nextheight; if ( fHelp || params.size() != 2 ) - throw runtime_error("nspv_proof prevheight nextheight\n"); + throw runtime_error("nspv_hdrsproof prevheight nextheight\n"); prevheight = atoi((char *)params[0].get_str().c_str()); nextheight = atoi((char *)params[1].get_str().c_str()); return(NSPV_hdrsproof(prevheight,nextheight)); From 2338d9c0688483cba9af753f657fc36f0e669fed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 19:20:17 -1100 Subject: [PATCH 132/659] Issue netinfo via rpc --- src/komodo_nSPV.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e0eb47988..03997362c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -826,16 +826,35 @@ UniValue NSPV_ntz_json(struct NSPV_ntz *ptr) return(result); } -UniValue NSPV_getinfo_json() +UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr) { UniValue result(UniValue::VOBJ); result.push_back(Pair("result","success")); - result.push_back(Pair("height",(int64_t)NSPV_inforesult.height)); - result.push_back(Pair("chaintip",NSPV_inforesult.blockhash.GetHex())); - result.push_back(Pair("notarization",NSPV_ntz_json(&NSPV_inforesult.notarization))); + result.push_back(Pair("height",(int64_t)ptr->height)); + result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); + result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); return(result); } +UniValue NSPV_getinfo_json() +{ + uint8_t msg[64]; int32_t i,len = 0; struct NSPV_inforesp I; + if ( NSPV_inforesult.height != 0 ) + return(_NSPV_getinfo_json(&NSPV_inforesult)); + msg[len++] = NSPV_INFO; + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + { + for (i=0; i<10; i++) + { + usleep(100000); + if ( NSPV_inforesult.height != 0 ) + return(_NSPV_getinfo_json(&NSPV_inforesult)); + } + } + memset(&I,0,sizeof(I)); + return(_NSPV_getinfo_json(&NSPV_inforesult)); +} + UniValue NSPV_utxoresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) { UniValue array(UniValue::VARR); int32_t i; From 99fb4fc1948ea98a3c2f1f4c5c7be1340c48583a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 20:05:17 -1100 Subject: [PATCH 133/659] Implement NSPV_getnotarization_txid --- src/komodo_nSPV.h | 21 ++++++++++----------- src/notarisationdb.cpp | 27 +++++++++++++++++++++++++++ src/notarisationdb.h | 1 + 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 03997362c..f84bc358a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -351,21 +351,20 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) // on fullnode: // NSPV_get... functions need to return the exact serialized length, which is the size of the structure minus size of pointers, plus size of allocated data +#include "notarisationdb.h" + uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) { - uint256 ntztxid; - if ( ntzheightp == 0 ) // search consecutive blocks + uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? "KMD" : ASSETCHAINS_SYMBOL; + memset(&txid,0,sizeof(txid)); + *ntzheightp = 0; + int32_t matchedHeight = ScanNotarisationsDB(height,symbol,1440,nota); + if ( matchedHeight != 0 ) { - *ntzheightp = height + 1; - // iterate + *ntzheightp = matchedHeight; + txid = nota.first; } - else - { - // check *ntzheightp - } - // find notarization for height, return its txid and set *ntzheightp - fprintf(stderr,"implement NSPV_getnotarization_txid\n"); - return(ntztxid); + return(txid); } int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 201743dbd..b148deccf 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -135,3 +135,30 @@ int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Not } return 0; } + +int ScanNotarisationsDB2(int height, std::string symbol, int scanLimitBlocks, Notarisation& out) +{ + int32_t i,maxheight,ht; + maxheight = chainActive.Height(); + if ( height < 0 || height > maxheight ) + return false; + for (i=0; i maxheight ) + break; + NotarisationsInBlock notarisations; + uint256 blockHash = *chainActive[ht]->phashBlock; + if ( !GetBlockNotarisations(blockHash,notarisations) ) + continue; + BOOST_FOREACH(Notarisation& nota,notarisations) + { + if ( strcmp(nota.second.symbol,symbol.data()) == 0 ) + { + out = nota; + return(ht); + } + } + } + return 0; +} diff --git a/src/notarisationdb.h b/src/notarisationdb.h index 38b7b3671..af5d4df28 100644 --- a/src/notarisationdb.h +++ b/src/notarisationdb.h @@ -24,6 +24,7 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n); void WriteBackNotarisations(const NotarisationsInBlock notarisations, CDBBatch &batch); void EraseBackNotarisations(const NotarisationsInBlock notarisations, CDBBatch &batch); int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Notarisation& out); +int ScanNotarisationsDB2(int height, std::string symbol, int scanLimitBlocks, Notarisation& out); bool IsTXSCL(const char* symbol); #endif /* NOTARISATIONDB_H */ From 89bcb9210af158028e4e18b00b40982c72d4737a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 20:07:13 -1100 Subject: [PATCH 134/659] Char * --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f84bc358a..f7a89bc56 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -355,7 +355,7 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) { - uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? "KMD" : ASSETCHAINS_SYMBOL; + uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(&txid,0,sizeof(txid)); *ntzheightp = 0; int32_t matchedHeight = ScanNotarisationsDB(height,symbol,1440,nota); From 11d3ffa86487db0a2650add40f6e178191ae1cf9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 21:18:25 -1100 Subject: [PATCH 135/659] Complete nota DB searching --- src/komodo_nSPV.h | 113 ++++++++++++++++++++++++++++---------------- src/komodo_notary.h | 24 ---------- 2 files changed, 72 insertions(+), 65 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f7a89bc56..d91b59998 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -358,7 +358,7 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(&txid,0,sizeof(txid)); *ntzheightp = 0; - int32_t matchedHeight = ScanNotarisationsDB(height,symbol,1440,nota); + int32_t matchedHeight = ScanNotarisationsDB2(height,symbol,1440,nota); if ( matchedHeight != 0 ) { *ntzheightp = matchedHeight; @@ -367,16 +367,81 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) return(txid); } +uint256 NSPV_extract_desttxid(char *symbol,std::vector opret) +{ + uint256 desttxid; + memcpy(&desttxid,&opret[2 + 4 + 32],sizeof(desttxid)); + return(desttxid); +} + +int32_t komodo_notarized_bracket(uint256 txids[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) +{ + int32_t ntzht; Notarisation nota; char *symbol; + symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; + memset(txids,0,sizeof(*txids)*2); + memset(desttxids,0,sizeof(*desttxids)*2); + memset(ntzheights,0,sizeof(*ntzheights)*2); + if ( (ntzht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 ) + return(-1); + txids[0] = nota.first; + ntzheights[0] = ntzheight; + desttxids[0] = NSPV_extract_desttxid(symbol,E_MARSHAL(ss << nota.second)); + if ( ntzht == height ) + { + txids[1] = txids[0]; + ntzheights[1] = ntzht; + desttxids[1] = desttxids[0]; + return(0); + } + if ( (ntzht= ScanNotarisationsDB(height,symbol,1440,nota)) != 0 ) + { + txids[1] = nota.first; + ntzheights[1] = ntzht; + desttxids[1] = NSPV_extract_desttxid(symbol,E_MARSHAL(ss << nota.second)); + } + return(0); +} + +int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,uint256 desttxid,int32_t ntzheight) +{ + uint64_t value; uint32_t tiptime=0,txheighttime; + ptr->blockhash = *chainActive[ntzheight]->phashBlock; + ptr->height = ntzheight; + komodo_interest_args(&txheighttime,&ptr->txidheight,&tiptime,&value,ntztxid,0); + ptr->othertxid = desttxid; + ptr->txid = ntztxid; + return(0); +} + +int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) +{ + uint256 txids[2],desttxids[2]; int32_t ntzheights[2]; + if ( komodo_notarized_bracket(txids,ntzheights,height) == 0 ) + { + if ( ntzheights[0] != 0 ) + { + if ( NSPV_ntzextract(&ptr->prevntz,txids[0],desttxids[0],ntzheights[0]) < 0 ) + return(-1); + } + if ( ntzheights[1] != 0 ) + { + if ( NSPV_ntzextract(&ptr->nextntz,txids[1],desttxids[1],ntzheights[1]) < 0 ) + return(-1); + } + } + return(sizeof(*ptr)); +} + int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) { - int32_t prevMoMheight,len = 0; CBlockIndex *pindex; + int32_t prevMoMheight,len = 0; CBlockIndex *pindex; struct NSPV_ntzsresp pair; if ( (pindex= chainActive.LastTip()) != 0 ) { ptr->height = pindex->GetHeight(); ptr->blockhash = pindex->GetBlockHash(); - ptr->notarization.height = komodo_notarized_height(&prevMoMheight,&ptr->notarization.blockhash,&ptr->notarization.othertxid); - ptr->notarization.txidheight = 0; - ptr->notarization.txid = NSPV_getnotarization_txid(&ptr->notarization.txidheight,ptr->notarization.height); + if ( NSPV_getntzsresp(&pair,ptr->height) < 0 ) + return(-1); + ptr->notarization = pair.prevntz; return(sizeof(*ptr)); } else return(-1); } @@ -425,41 +490,6 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check return(0); } -int32_t NSPV_npextract(struct NSPV_ntz *ptr,struct notarized_checkpoint *np) -{ - int32_t ntzheight; - ptr->blockhash = np->notarized_hash; - ptr->height = np->notarized_height; - ptr->txidheight = np->nHeight; - ptr->othertxid = np->notarized_desttxid; - ntzheight = ptr->txidheight; - ptr->txid = NSPV_getnotarization_txid(&ntzheight,ptr->height); - if ( ntzheight != ptr->txidheight ) - { - fprintf(stderr,"NSPV_npextract ntzheight.%d != ptr->txidheight.%d\n",ntzheight,ptr->txidheight); - return(-1); - } else return(0); -} - -int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) -{ - struct notarized_checkpoint *nps[2]; - if ( komodo_notarized_bracket(nps,height) == 0 ) - { - if ( nps[0] != 0 ) - { - if ( NSPV_npextract(&ptr->prevntz,nps[0]) < 0 ) - return(-1); - } - if ( nps[1] != 0 ) - { - if ( NSPV_npextract(&ptr->nextntz,nps[1]) < 0 ) - return(-1); - } - } - return(sizeof(*ptr)); -} - uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) { CTransaction tx; uint8_t *rawtx = 0; @@ -743,7 +773,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } } -// nSPV client +// nSPV client. VERY simplistic "single threaded" networking model. for production GUI best to multithread, etc. + CAmount AmountFromValue(const UniValue& value); int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index a80e035bd..028bc4dc2 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -392,30 +392,6 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in return(0); } -int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height) -{ - int32_t i; struct notarized_checkpoint *np; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; - memset(nps,0,sizeof(*nps)*2); - if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) - { - if ( sp->NUM_NPOINTS > 0 ) - { - for (i=0; iNUM_NPOINTS; i++) - { - np = &sp->NPOINTS[i]; - if ( np->nHeight <= height ) - nps[0] = np; - else - { - nps[1] = np; - return(0); - } - } - } - } - return(-1); -} - int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp) { struct notarized_checkpoint *np = 0; int32_t i=0,flag = 0; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; From 5c3ee387428042a9b3d49ecb2448a88d99106fc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 21:26:43 -1100 Subject: [PATCH 136/659] Syntax --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d91b59998..eb7ecbba3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -384,7 +384,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],uint256 desttxids[2],int32_t n if ( (ntzht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 ) return(-1); txids[0] = nota.first; - ntzheights[0] = ntzheight; + ntzheights[0] = ntzht; desttxids[0] = NSPV_extract_desttxid(symbol,E_MARSHAL(ss << nota.second)); if ( ntzht == height ) { @@ -416,7 +416,7 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,uint256 desttxid,in int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) { uint256 txids[2],desttxids[2]; int32_t ntzheights[2]; - if ( komodo_notarized_bracket(txids,ntzheights,height) == 0 ) + if ( komodo_notarized_bracket(txids,desttxids,ntzheights,height) == 0 ) { if ( ntzheights[0] != 0 ) { From 23bbfbd7b29c224f88e5337ddd6b304d17e42b2a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 21:32:41 -1100 Subject: [PATCH 137/659] Off by 1 --- src/komodo_nSPV.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index eb7ecbba3..be755fa79 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -358,7 +358,7 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(&txid,0,sizeof(txid)); *ntzheightp = 0; - int32_t matchedHeight = ScanNotarisationsDB2(height,symbol,1440,nota); + int32_t matchedHeight = ScanNotarisationsDB2(height+1,symbol,1440,nota); if ( matchedHeight != 0 ) { *ntzheightp = matchedHeight; @@ -369,8 +369,9 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) uint256 NSPV_extract_desttxid(char *symbol,std::vector opret) { - uint256 desttxid; - memcpy(&desttxid,&opret[2 + 4 + 32],sizeof(desttxid)); + uint256 desttxid; int32_t i; + for (i=0; i<32; i++) + ((uint8_t *)&desttxid)[i] = opret[2 + 4 + 32 + 31 - i]; return(desttxid); } From a20de3fa836f3f06e9dd6f5fa935840686cfc044 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 5 Jul 2019 10:41:42 +0200 Subject: [PATCH 138/659] Fix KOMODO_EARLYTXID --- src/komodo_utils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 02bdb07ad..a4af4da6f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1787,9 +1787,10 @@ void komodo_args(char *argv0) printf("KOMODO_REWIND %d\n",KOMODO_REWIND); } KOMODO_EARLYTXID = Parseuint256(GetArg("-earlytxid","0").c_str()); - if (KOMODO_EARLYTXID!=zeroid && (tx_height(KOMODO_EARLYTXID)==0 || tx_height(KOMODO_EARLYTXID)>100)) + CTransaction tx; uint256 blockhash; + if (KOMODO_EARLYTXID!=zeroid && myGetTransaction(KOMODO_EARLYTXID,tx,blockhash) && (mapBlockIndex[blockhash]->GetHeight() == 0 || mapBlockIndex[blockhash]->GetHeight() > 100)) { - fprintf(stderr,"earlytx can be only in first 100 blocks or does not exist\n"); + fprintf(stderr,"error: earlytx can be only in first 100 blocks or tx does not exist\n"); StartShutdown(); } ASSETCHAINS_EARLYTXIDCONTRACT = GetArg("-ac_earlytxidcontract",0); From 1c313a4adb594e94864a38fbca529b9e658491cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 21:44:17 -1100 Subject: [PATCH 139/659] Test --- src/komodo_nSPV.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index be755fa79..64d09d2f2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -358,7 +358,7 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(&txid,0,sizeof(txid)); *ntzheightp = 0; - int32_t matchedHeight = ScanNotarisationsDB2(height+1,symbol,1440,nota); + int32_t matchedHeight = ScanNotarisationsDB2(height,symbol,1440,nota); if ( matchedHeight != 0 ) { *ntzheightp = matchedHeight; @@ -370,8 +370,11 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) uint256 NSPV_extract_desttxid(char *symbol,std::vector opret) { uint256 desttxid; int32_t i; + for (i=0; i Date: Thu, 4 Jul 2019 21:52:43 -1100 Subject: [PATCH 140/659] +print --- src/komodo_nSPV.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 64d09d2f2..5305fb434 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -370,11 +370,17 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) uint256 NSPV_extract_desttxid(char *symbol,std::vector opret) { uint256 desttxid; int32_t i; - for (i=0; i Date: Thu, 4 Jul 2019 22:03:08 -1100 Subject: [PATCH 141/659] Line up nth bracket --- src/komodo_nSPV.h | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 5305fb434..f717798a4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -367,57 +367,59 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) return(txid); } -uint256 NSPV_extract_desttxid(char *symbol,std::vector opret) +uint256 NSPV_extract_desttxid(int32_t *heightp,char *symbol,std::vector opret) { uint256 desttxid; int32_t i; for (i=0; i<32; i++) fprintf(stderr,"%02x",opret[i]); fprintf(stderr," blockhash, "); for (i=0; i<4; i++) - fprintf(stderr,"%02x",opret[i]); + fprintf(stderr,"%02x",opret[32+i]); fprintf(stderr," height, "); + iguana_rwnum(1,&opret[32],sizeof(*heightp),heightp); for (i=0; i<32; i++) - fprintf(stderr,"%02x",opret[i]); + fprintf(stderr,"%02x",opret[36+i]); fprintf(stderr," desttxid\n"); for (i=0; i<32; i++) ((uint8_t *)&desttxid)[i] = opret[4 + 32 + 31 - i]; return(desttxid); } -int32_t komodo_notarized_bracket(uint256 txids[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) +int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) { - int32_t ntzht; Notarisation nota; char *symbol; + int32_t txidht; Notarisation nota; char *symbol; symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(txids,0,sizeof(*txids)*2); memset(desttxids,0,sizeof(*desttxids)*2); memset(ntzheights,0,sizeof(*ntzheights)*2); - if ( (ntzht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 ) + memset(txidhts,0,sizeof(*txidhts)*2); + if ( (txidht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 ) return(-1); txids[0] = nota.first; - ntzheights[0] = ntzht; - desttxids[0] = NSPV_extract_desttxid(symbol,E_MARSHAL(ss << nota.second)); - if ( ntzht == height ) + txidhts[0] = txidht; + desttxids[0] = NSPV_extract_desttxid(&ntzheights[0],symbol,E_MARSHAL(ss << nota.second)); + if ( ntzheights[0] == height ) { txids[1] = txids[0]; - ntzheights[1] = ntzht; + txidhts[1] = txidhts[0]; + ntzheights[1] = ntzheights[0]; desttxids[1] = desttxids[0]; return(0); } - if ( (ntzht= ScanNotarisationsDB2(height+1,symbol,1440,nota)) != 0 ) + if ( (txidht= ScanNotarisationsDB2(height+1,symbol,1440,nota)) != 0 ) { txids[1] = nota.first; - ntzheights[1] = ntzht; - desttxids[1] = NSPV_extract_desttxid(symbol,E_MARSHAL(ss << nota.second)); + txidhts[1] = txidht; + desttxids[1] = NSPV_extract_desttxid(&ntzheights[1],symbol,E_MARSHAL(ss << nota.second)); } return(0); } -int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,uint256 desttxid,int32_t ntzheight) +int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint256 desttxid,int32_t ntzheight) { - uint64_t value; uint32_t tiptime=0,txheighttime; ptr->blockhash = *chainActive[ntzheight]->phashBlock; ptr->height = ntzheight; - komodo_interest_args(&txheighttime,&ptr->txidheight,&tiptime,&value,ntztxid,0); + ptr->txidheight = txidht; ptr->othertxid = desttxid; ptr->txid = ntztxid; return(0); @@ -425,17 +427,17 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,uint256 desttxid,in int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) { - uint256 txids[2],desttxids[2]; int32_t ntzheights[2]; - if ( komodo_notarized_bracket(txids,desttxids,ntzheights,height) == 0 ) + uint256 txids[2],desttxids[2]; int32_t ntzheights[2],txidhts[2]; + if ( komodo_notarized_bracket(txids,txidhts,desttxids,ntzheights,height) == 0 ) { if ( ntzheights[0] != 0 ) { - if ( NSPV_ntzextract(&ptr->prevntz,txids[0],desttxids[0],ntzheights[0]) < 0 ) + if ( NSPV_ntzextract(&ptr->prevntz,txids[0],txidhts[0],desttxids[0],ntzheights[0]) < 0 ) return(-1); } if ( ntzheights[1] != 0 ) { - if ( NSPV_ntzextract(&ptr->nextntz,txids[1],desttxids[1],ntzheights[1]) < 0 ) + if ( NSPV_ntzextract(&ptr->nextntz,txids[1],txidhts[1],desttxids[1],ntzheights[1]) < 0 ) return(-1); } } From b512fb08c9edb0e876402727a65329239e721fb4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 22:12:19 -1100 Subject: [PATCH 142/659] Rev dir --- src/komodo_nSPV.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f717798a4..d70c1da33 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -376,12 +376,12 @@ uint256 NSPV_extract_desttxid(int32_t *heightp,char *symbol,std::vector for (i=0; i<4; i++) fprintf(stderr,"%02x",opret[32+i]); fprintf(stderr," height, "); - iguana_rwnum(1,&opret[32],sizeof(*heightp),heightp); + iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); for (i=0; i<32; i++) fprintf(stderr,"%02x",opret[36+i]); fprintf(stderr," desttxid\n"); for (i=0; i<32; i++) - ((uint8_t *)&desttxid)[i] = opret[4 + 32 + 31 - i]; + ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; return(desttxid); } @@ -398,6 +398,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des txids[0] = nota.first; txidhts[0] = txidht; desttxids[0] = NSPV_extract_desttxid(&ntzheights[0],symbol,E_MARSHAL(ss << nota.second)); + fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); if ( ntzheights[0] == height ) { txids[1] = txids[0]; @@ -406,7 +407,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des desttxids[1] = desttxids[0]; return(0); } - if ( (txidht= ScanNotarisationsDB2(height+1,symbol,1440,nota)) != 0 ) + if ( (txidht= ScanNotarisationsDB2(height,symbol,1440,nota)) != 0 ) { txids[1] = nota.first; txidhts[1] = txidht; @@ -428,6 +429,8 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) { uint256 txids[2],desttxids[2]; int32_t ntzheights[2],txidhts[2]; + if ( height < chainActive.LastTip()->GetHeight() ) + height++; if ( komodo_notarized_bracket(txids,txidhts,desttxids,ntzheights,height) == 0 ) { if ( ntzheights[0] != 0 ) From 9e392544bec0bbbed80ab000d38f1a25bfd382af Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 22:26:36 -1100 Subject: [PATCH 143/659] Remove +1 adjustment --- src/komodo_nSPV.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d70c1da33..9b14ddbd2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -370,16 +370,16 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) uint256 NSPV_extract_desttxid(int32_t *heightp,char *symbol,std::vector opret) { uint256 desttxid; int32_t i; - for (i=0; i<32; i++) - fprintf(stderr,"%02x",opret[i]); - fprintf(stderr," blockhash, "); - for (i=0; i<4; i++) - fprintf(stderr,"%02x",opret[32+i]); - fprintf(stderr," height, "); + //for (i=0; i<32; i++) + // fprintf(stderr,"%02x",opret[i]); + //fprintf(stderr," blockhash, "); + //for (i=0; i<4; i++) + // fprintf(stderr,"%02x",opret[32+i]); + //fprintf(stderr," height, "); iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); - for (i=0; i<32; i++) - fprintf(stderr,"%02x",opret[36+i]); - fprintf(stderr," desttxid\n"); + //for (i=0; i<32; i++) + // fprintf(stderr,"%02x",opret[36+i]); + //fprintf(stderr," desttxid\n"); for (i=0; i<32; i++) ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; return(desttxid); @@ -398,7 +398,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des txids[0] = nota.first; txidhts[0] = txidht; desttxids[0] = NSPV_extract_desttxid(&ntzheights[0],symbol,E_MARSHAL(ss << nota.second)); - fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); + //fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); if ( ntzheights[0] == height ) { txids[1] = txids[0]; @@ -429,8 +429,8 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) { uint256 txids[2],desttxids[2]; int32_t ntzheights[2],txidhts[2]; - if ( height < chainActive.LastTip()->GetHeight() ) - height++; + //if ( height < chainActive.LastTip()->GetHeight() ) + // height++; if ( komodo_notarized_bracket(txids,txidhts,desttxids,ntzheights,height) == 0 ) { if ( ntzheights[0] != 0 ) From c231439bb316890664b6f09ec0a6a9b8589e0282 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 22:36:47 -1100 Subject: [PATCH 144/659] Tweak --- src/komodo_nSPV.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9b14ddbd2..1af2f4570 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -398,8 +398,8 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des txids[0] = nota.first; txidhts[0] = txidht; desttxids[0] = NSPV_extract_desttxid(&ntzheights[0],symbol,E_MARSHAL(ss << nota.second)); - //fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); - if ( ntzheights[0] == height ) + fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); + if ( ntzheights[0] == height-1 ) { txids[1] = txids[0]; txidhts[1] = txidhts[0]; @@ -429,8 +429,8 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) { uint256 txids[2],desttxids[2]; int32_t ntzheights[2],txidhts[2]; - //if ( height < chainActive.LastTip()->GetHeight() ) - // height++; + if ( height < chainActive.LastTip()->GetHeight() ) + height++; if ( komodo_notarized_bracket(txids,txidhts,desttxids,ntzheights,height) == 0 ) { if ( ntzheights[0] != 0 ) @@ -454,7 +454,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) { ptr->height = pindex->GetHeight(); ptr->blockhash = pindex->GetBlockHash(); - if ( NSPV_getntzsresp(&pair,ptr->height) < 0 ) + if ( NSPV_getntzsresp(&pair,ptr->height-1) < 0 ) return(-1); ptr->notarization = pair.prevntz; return(sizeof(*ptr)); From 66c144d323c75de4df813a816575b165d2340e77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 23:05:21 -1100 Subject: [PATCH 145/659] Filenames add "Tx" --- src/komodo_nSPV.h | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1af2f4570..f67fe7385 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -284,7 +284,7 @@ struct NSPV_ntzsproofresp struct NSPV_ntzproofshared common; uint256 prevtxid,nexttxid; int32_t pad32,prevtxidht,nexttxidht; - uint16_t prevlen,nextlen; + uint16_t prevtxlen,nexttxlen; uint8_t *prevntz,*nextntz; }; @@ -297,8 +297,8 @@ int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzs len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevtxidht),&ptr->prevtxidht); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nexttxidht),&ptr->nexttxidht); - len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->prevlen,&ptr->prevntz); - len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->nextlen,&ptr->nextntz); + len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->prevtxlen,&ptr->prevntz); + len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->nexttxlen,&ptr->nextntz); return(len); } @@ -398,8 +398,9 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des txids[0] = nota.first; txidhts[0] = txidht; desttxids[0] = NSPV_extract_desttxid(&ntzheights[0],symbol,E_MARSHAL(ss << nota.second)); - fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); - if ( ntzheights[0] == height-1 ) + if ( height != 2668 ) + fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); + if ( ntzheights[0] == height-1 ) // offset the +1 from caller { txids[1] = txids[0]; txidhts[1] = txidhts[0]; @@ -606,11 +607,11 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 } } ptr->prevtxid = NSPV_getnotarization_txid(&ptr->prevtxidht,prevht); - ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevlen,ptr->prevtxid); + ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid); ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); - ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nextlen,ptr->nexttxid); - //fprintf(stderr,"prevlen.%d nextlen.%d size %ld -> %ld\n",ptr->prevlen,ptr->nextlen,sizeof(*ptr),sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); - return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); + ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid); + //fprintf(stderr,"prevtxlen.%d nexttxlen.%d size %ld -> %ld\n",ptr->prevtxlen,ptr->nexttxlen,sizeof(*ptr),sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); + return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevtxlen + ptr->nexttxlen); } int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) @@ -884,8 +885,8 @@ UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr) UniValue NSPV_getinfo_json() { uint8_t msg[64]; int32_t i,len = 0; struct NSPV_inforesp I; - if ( NSPV_inforesult.height != 0 ) - return(_NSPV_getinfo_json(&NSPV_inforesult)); + //if ( NSPV_inforesult.height != 0 ) + // return(_NSPV_getinfo_json(&NSPV_inforesult)); msg[len++] = NSPV_INFO; if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { @@ -961,10 +962,10 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("nextht",(int64_t)ptr->common.nextht)); result.push_back(Pair("prevtxid",ptr->prevtxid.GetHex())); result.push_back(Pair("prevtxidht",(int64_t)ptr->prevtxidht)); - result.push_back(Pair("prevlen",(int64_t)ptr->prevlen)); + result.push_back(Pair("prevtxlen",(int64_t)ptr->prevtxlen)); result.push_back(Pair("nexttxid",ptr->nexttxid.GetHex())); result.push_back(Pair("nexttxidht",(int64_t)ptr->nexttxidht)); - result.push_back(Pair("nextlen",(int64_t)ptr->prevlen)); + result.push_back(Pair("nexttxlen",(int64_t)ptr->prevtxlen)); result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs))); return(result); From 95386444da68c8d290b22683e9982564cf39e264 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 23:16:37 -1100 Subject: [PATCH 146/659] Polling tweaks netinfo --- src/komodo_nSPV.h | 63 +++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f67fe7385..5b9e8eca0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -790,6 +790,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } // nSPV client. VERY simplistic "single threaded" networking model. for production GUI best to multithread, etc. +#define NSPV_POLLITERS 15 +#define NSPV_POLLMICROS 100000 CAmount AmountFromValue(const UniValue& value); int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); @@ -882,25 +884,6 @@ UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr) return(result); } -UniValue NSPV_getinfo_json() -{ - uint8_t msg[64]; int32_t i,len = 0; struct NSPV_inforesp I; - //if ( NSPV_inforesult.height != 0 ) - // return(_NSPV_getinfo_json(&NSPV_inforesult)); - msg[len++] = NSPV_INFO; - if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) - { - for (i=0; i<10; i++) - { - usleep(100000); - if ( NSPV_inforesult.height != 0 ) - return(_NSPV_getinfo_json(&NSPV_inforesult)); - } - } - memset(&I,0,sizeof(I)); - return(_NSPV_getinfo_json(&NSPV_inforesult)); -} - UniValue NSPV_utxoresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) { UniValue array(UniValue::VARR); int32_t i; @@ -1003,6 +986,28 @@ UniValue NSPV_login(char *wifstr) return(result); } +UniValue NSPV_getinfo_json() +{ + uint8_t msg[64]; int32_t i,len = 0; struct NSPV_inforesp I; + NSPV_inforesp_purge(&NSPV_inforesult); + msg[len++] = NSPV_INFO; + for (iters=0; iters<3; iters++) + { + fprintf(stderr,"issue getinfo\n"); + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + { + for (i=0; i>1) != 0 ) { - for (i=0; i<10; i++) + for (i=0; i= NSPV_inforesult.height ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); } @@ -1046,9 +1051,9 @@ UniValue NSPV_notarizations(int32_t height) len += iguana_rwnum(1,&msg[len],sizeof(height),&height); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { - for (i=0; i<10; i++) + for (i=0; i= height ) return(NSPV_ntzs_json(&NSPV_ntzsresult)); } @@ -1067,9 +1072,9 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { - for (i=0; i<10; i++) + for (i=0; i= nextheight ) return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); } @@ -1089,9 +1094,9 @@ UniValue NSPV_txproof(uint256 txid,int32_t height) //fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { - for (i=0; i<10; i++) + for (i=0; i>1) != 0 ) { - for (i=0; i<10; i++) + for (i=0; i Date: Thu, 4 Jul 2019 23:22:44 -1100 Subject: [PATCH 147/659] Items --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 5b9e8eca0..b8bb5da2f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -988,7 +988,7 @@ UniValue NSPV_login(char *wifstr) UniValue NSPV_getinfo_json() { - uint8_t msg[64]; int32_t i,len = 0; struct NSPV_inforesp I; + uint8_t msg[64]; int32_t i,iters,len = 0; struct NSPV_inforesp I; NSPV_inforesp_purge(&NSPV_inforesult); msg[len++] = NSPV_INFO; for (iters=0; iters<3; iters++) From 20d3e7195f85f82a3f2f077013e5b1328b97008c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 23:28:40 -1100 Subject: [PATCH 148/659] +prints --- src/komodo_nSPV.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b8bb5da2f..a570112a9 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -823,7 +823,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) flag = 1; pnode = ptr; break; - } // else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); + } else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); } } else flag = 1; if ( pnode != 0 ) @@ -831,11 +831,11 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - //fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); + fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; return(pnode); - } + } else fprintf(stderr,"no pnodes\n"); return(0); } From 6539eaa8bce0b979258ab0978c2075a265485863 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 23:29:02 -1100 Subject: [PATCH 149/659] Sleeps --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a570112a9..529919539 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1002,7 +1002,7 @@ UniValue NSPV_getinfo_json() if ( NSPV_inforesult.height != 0 ) return(_NSPV_getinfo_json(&NSPV_inforesult)); } - } + } else sleep(1); } memset(&I,0,sizeof(I)); return(_NSPV_getinfo_json(&NSPV_inforesult)); From 96cd0dc5bd3b00694ffc6985db185ed857d293e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 23:33:18 -1100 Subject: [PATCH 150/659] Clear garbage values --- src/komodo_nSPV.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 529919539..9afa9d19e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -816,6 +816,8 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) LOCK(cs_vNodes); BOOST_FOREACH(CNode *ptr,vNodes) { + if ( ptr->prevtimes[ind] > timestamp ) + ptr->prevtimes[ind] = 0; if ( ptr->hSocket == INVALID_SOCKET ) continue; if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) From 0fa040f54e510340252cb5903b0cdcb2ec0f6426 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 23:36:26 -1100 Subject: [PATCH 151/659] Clear full node prevtimes --- src/komodo_nSPV.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9afa9d19e..47926fb71 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -641,6 +641,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { if ( (ind= request[0]>>1) >= sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes) ) ind = (int32_t)(sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes)) - 1; + if ( pfrom->prevtimes[ind] > timestamp ) + pfrom->prevtimes[ind] = 0; if ( request[0] == NSPV_INFO ) // info { //fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); From 3c8826dab3cf5e6ae55ae0df46e0c065a2ecb59d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jul 2019 23:57:03 -1100 Subject: [PATCH 152/659] -print --- src/komodo_nSPV.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 47926fb71..1a079eb70 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -827,7 +827,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) flag = 1; pnode = ptr; break; - } else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); + } //else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); } } else flag = 1; if ( pnode != 0 ) @@ -835,7 +835,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); + //fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; return(pnode); @@ -997,7 +997,7 @@ UniValue NSPV_getinfo_json() msg[len++] = NSPV_INFO; for (iters=0; iters<3; iters++) { - fprintf(stderr,"issue getinfo\n"); + //fprintf(stderr,"issue getinfo\n"); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i response) // received a r case NSPV_INFORESP: NSPV_inforesp_purge(&NSPV_inforesult); NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); - fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status + //fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status break; case NSPV_UTXOSRESP: NSPV_utxosresp_purge(&NSPV_utxosresult); From 085f99d44d2e64774cf32071ce22705393321e32 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 00:35:44 -1100 Subject: [PATCH 153/659] Add coinaddr to utxos --- src/komodo_nSPV.h | 28 ++++++++++++++++++++++++---- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcdump.cpp | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1a079eb70..d3d17221b 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -119,6 +119,7 @@ int32_t NSPV_rwutxoresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxoresp struct NSPV_utxosresp { struct NSPV_utxoresp *utxos; + char coinaddr[64]; int64_t total,interest; int32_t nodeheight; uint16_t numutxos,pad16; @@ -139,6 +140,16 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); + if ( rwflag != 0 ) + { + memcpy(&serialized[len],ptr->coinaddr,sizeof(ptr->coinaddr)); + len += sizeof(ptr->coinaddr); + } + else + { + memcpy(ptr->coinaddr,&serialized[len],sizeof(ptr->coinaddr)); + len += sizeof(ptr->coinaddr); + } return(len); } @@ -469,6 +480,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check SetCCunspents(unspentOutputs,coinaddr,false); maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); + strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); @@ -910,6 +922,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) UniValue result(UniValue::VOBJ); result.push_back(Pair("result","success")); result.push_back(Pair("utxos",NSPV_utxoresp_json(ptr->utxos,ptr->numutxos))); + result.push_back(Pair("address",ptr->coinaddr)); result.push_back(Pair("height",(int64_t)ptr->nodeheight)); result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); result.push_back(Pair("balance",(double)ptr->total/COIN)); @@ -1218,12 +1231,19 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages } } }*/ - if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) + if ( KOMODO_NSPV != 0 ) { - len = 0; - msg[len++] = NSPV_INFO; - NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); + if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) + { + len = 0; + msg[len++] = NSPV_INFO; + NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); + } } } +UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! +{ + +} #endif // KOMODO_NSPV_H diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 810848f74..c6a51d568 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -424,6 +424,7 @@ static const CRPCCommand vRPCCommands[] = { "nSPV", "nspv_notarizations", &nspv_notarizations, true }, { "nSPV", "nspv_hdrsproof", &nspv_hdrsproof, true }, { "nSPV", "nspv_txproof", &nspv_txproof, true }, + { "nSPV", "nspv_send", &nspv_send, true }, // rewards { "rewards", "rewardslist", &rewardslist, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 64c78ea47..37cb3d26a 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -462,6 +462,7 @@ extern UniValue nspv_spentinfo(const UniValue& params, bool fHelp); extern UniValue nspv_notarizations(const UniValue& params, bool fHelp); extern UniValue nspv_hdrsproof(const UniValue& params, bool fHelp); extern UniValue nspv_txproof(const UniValue& params, bool fHelp); +extern UniValue nspv_send(const UniValue& params, bool fHelp); extern UniValue getblocksubsidy(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index f7357aecf..b13a2b6c9 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -975,6 +975,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) UniValue NSPV_getinfo_json(); UniValue NSPV_login(char *wifstr); UniValue NSPV_addressutxos(char *coinaddr); +UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); UniValue NSPV_notarizations(int32_t height); UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight); @@ -1043,3 +1044,17 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp) height = atoi((char *)params[1].get_str().c_str()); return(NSPV_txproof(txid,height)); } + +UniValue nspv_send(const UniValue& params, bool fHelp) +{ + uint64_t satoshis; + if ( fHelp || params.size() != 2 ) + throw runtime_error("nspv_send destaddr amount\n"); + if ( NSPV_address.size() == 0 ) + throw runtime_error("to nspv_send you need an active nspv_login\n"); + satoshis = atof(params[1].get_str().c_str())*COIN + 0.0000000049; + if ( satoshis < 1000 ) + throw runtime_error("amount too small\n"); + return(NSPV_send((char *)NSPV_address.c_str(),(char *)params[0].get_str().c_str(),satoshis)); +} + From c6f3c981ee33b41ecd05ee608018e1b3cf3984d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 01:46:29 -1100 Subject: [PATCH 154/659] Simple NSPV_send --- src/komodo_nSPV.h | 247 ++++++++++++++++++++++++++++++++++++-------- src/script/sign.cpp | 7 +- 2 files changed, 211 insertions(+), 43 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d3d17221b..4936c777d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -806,22 +806,28 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req // nSPV client. VERY simplistic "single threaded" networking model. for production GUI best to multithread, etc. #define NSPV_POLLITERS 15 #define NSPV_POLLMICROS 100000 +#define NSPV_MAXVINS 64 CAmount AmountFromValue(const UniValue& value); int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); uint32_t NSPV_lastinfo,NSPV_logintime; -char NSPV_wifstr[64]; +char NSPV_wifstr[64],NSPV_pubkeystr[67]; std::string NSPV_address; +CKey NSPV_key; struct NSPV_inforesp NSPV_inforesult; struct NSPV_utxosresp NSPV_utxosresult; struct NSPV_spentinfo NSPV_spentresult; struct NSPV_ntzsresp NSPV_ntzsresult; struct NSPV_ntzsproofresp NSPV_ntzsproofresult; struct NSPV_txproof NSPV_txproofresult; - struct NSPV_utxo *NSPV_utxos; +CKey *NSPV_defaultkey() +{ + return(&NSPV_key); +} + CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t flag = 0; uint32_t timestamp = (uint32_t)time(NULL); @@ -990,13 +996,13 @@ UniValue NSPV_login(char *wifstr) NSPV_logintime = (uint32_t)time(NULL); result.push_back(Pair("result","success")); result.push_back(Pair("status","wif will expire in 60 seconds")); - CKey key = DecodeSecret(wifstr); - CPubKey pubkey = key.GetPubKey(); - //assert(key.VerifyPubKey(pubkey)); + NSPV_key = DecodeSecret(wifstr); + CPubKey pubkey = NSPV_key.GetPubKey(); CKeyID vchAddress = pubkey.GetID(); NSPV_address = EncodeDestination(vchAddress); result.push_back(Pair("address",NSPV_address)); result.push_back(Pair("pubkey",HexStr(pubkey))); + strcpy(NSPV_pubkeystr,HexStr(pubkey).c_str()); result.push_back(Pair("wifprefix",(int64_t)data[0])); result.push_back(Pair("compressed",(int64_t)(data[len-5] == 1))); memset(data,0,sizeof(data)); @@ -1187,6 +1193,199 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r } } +int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) +{ + int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; + abovei = belowi = -1; + for (above=below=i=0; i value ) + { + gap = (atx_value - value); + if ( above == 0 || gap < above ) + { + above = gap; + abovei = i; + } + } + else + { + gap = (value - atx_value); + if ( below == 0 || gap < below ) + { + below = gap; + belowi = i; + } + } + //printf("value %.8f gap %.8f abovei.%d %.8f belowi.%d %.8f\n",dstr(value),dstr(gap),abovei,dstr(above),belowi,dstr(below)); + } + *aboveip = abovei; + *abovep = above; + *belowip = belowi; + *belowp = below; + //printf("above.%d below.%d\n",abovei,belowi); + if ( abovei >= 0 && belowi >= 0 ) + { + if ( above < (below >> 1) ) + return(abovei); + else return(belowi); + } + else if ( abovei >= 0 ) + return(abovei); + else return(belowi); +} + +int64_t NSPV_addinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) +{ + int32_t abovei,belowi,ind,vout,i,n = 0; int64_t threshold,above,below; int64_t remains,totalinputs = 0; CTransaction tx; struct NSPV_utxoresp *utxos,*up; + utxos = (struct NSPV_utxoresp *)calloc(NSPV_MAXVINS,sizeof(*utxos)); + if ( maxinputs > NSPV_MAXVINS ) + maxinputs = NSPV_MAXVINS; + if ( maxinputs > 0 ) + threshold = total/maxinputs; + else threshold = total; + remains = total; + for (i=0; i0; i++) + { + below = above = 0; + abovei = belowi = -1; + if ( NSPV_vinselect(&abovei,&above,&belowi,&below,utxos,n,remains) < 0 ) + { + printf("error finding unspent i.%d of %d, %.8f vs %.8f\n",i,n,(double)remains/COIN,(double)total/COIN); + free(utxos); + return(0); + } + if ( belowi < 0 || abovei >= 0 ) + ind = abovei; + else ind = belowi; + if ( ind < 0 ) + { + printf("error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,n,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); + free(utxos); + return(0); + } + up = &utxos[ind]; + mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); + totalinputs += up->nValue; + remains -= up->nValue; + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); + //fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); + if ( totalinputs >= total || (i+1) >= maxinputs ) + break; + } + free(utxos); + if ( totalinputs >= total ) + return(totalinputs); + return(0); +} + +std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret) +{ + auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + CTransaction vintx; std::string hex; uint256 hashBlock; int64_t change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n; + n = mtx.vout.size(); + for (i=0; i= totaloutputs+2*txfee ) + { + change = totalinputs - (totaloutputs+txfee); + mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(NSPV_pubkeystr) << OP_CHECKSIG)); + } + if ( opret.size() > 0 ) + mtx.vout.push_back(CTxOut(0,opret)); + PrecomputedTransactionData txdata(mtx); + n = mtx.vin.size(); + for (i=0; i data,opret; std::string hex; + data.resize(20); + memcpy(&data[0],&rmd160[1],20); + if ( NSPV_addinputs(mtx,satoshis+txfee,64) > 0 ) + { + mtx.vout.push_back(CTxOut(nValue,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); + hex = NSPV_signt(mtx,txfee,opret); + result.push_back(Pair("result","success")); + result.push_back(Pair("hex",hex)); + // prove all the vins + return(result); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt create tx")); + return(result); + } +} + void komodo_nSPV(CNode *pto) // polling loop from SendMessages { uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); @@ -1194,43 +1393,11 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages { fprintf(stderr,"scrub wif from NSPV memory\n"); memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); + memset(&NSPV_key,0,sizeof(NSPV_key)); NSPV_logintime = 0; } if ( (pto->nServices & NODE_NSPV) == 0 ) return; - /*if ( timestamp > pto->lastntzs || timestamp > pto->lastproof ) - { - for (i=0; i pto->lastntzs ) - { - request[0] = NSPV_NTZS; - pto->lastntzs = timestamp; - pto->PushMessage("getnSPV",request); - return; - } - else if ( timestamp > pto->lastproof ) - { - if ( NSPV_utxos[i].T.txlen == 0 ) - { - request[0] = NSPV_TXPROOF; - pto->lastproof = timestamp; - pto->PushMessage("getnSPV",request); - } - else // need space for the headers... - { - request[0] = NSPV_NTZPROOF; - pto->lastproof = timestamp; - pto->PushMessage("getnSPV",request); - } - return; - } - } - } - }*/ if ( KOMODO_NSPV != 0 ) { if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) @@ -1242,8 +1409,4 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages } } -UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! -{ - -} #endif // KOMODO_NSPV_H diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 685018828..fbc01669b 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -37,6 +37,7 @@ typedef vector valtype; extern uint8_t ASSETCHAINS_TXPOW; TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} +CKey *NSPV_defaultkey(); bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, const CKeyID& address, const CScript& scriptCode, uint32_t consensusBranchId, CKey *pprivKey, void *extraData) const { @@ -44,7 +45,11 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) - return false; + { + if ( (pprivKey= NSPV_defaultkey()) == 0 ) + return false; + else key = *pprivKey; + } uint256 hash; try { From 815ef1882ea979d687fe9a16cc9a275d583512ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 01:48:59 -1100 Subject: [PATCH 155/659] satoshis --- src/komodo_nSPV.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4936c777d..6dd7bdf53 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1193,13 +1193,15 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r } } +// nSPV wallet + int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) { int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; abovei = belowi = -1; for (above=below=i=0; itxid,up->vout,CScript())); - totalinputs += up->nValue; - remains -= up->nValue; + totalinputs += up->satoshis; + remains -= up->satoshis; utxos[ind] = utxos[--n]; memset(&utxos[n],0,sizeof(utxos[n])); //fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); @@ -1294,14 +1296,14 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret) CTransaction vintx; std::string hex; uint256 hashBlock; int64_t change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n; n = mtx.vout.size(); for (i=0; i= totaloutputs+2*txfee ) @@ -1318,7 +1320,7 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret) if ( GetTransaction(mtx.vin[i].prevout.hash,vintx,hashBlock,false) != 0 ) { utxovout = mtx.vin[i].prevout.n; - if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) + if ( SignTx(mtx,i,vintx.vout[utxovout].satoshis,vintx.vout[utxovout].scriptPubKey) == 0 ) fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask); } } @@ -1371,7 +1373,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al memcpy(&data[0],&rmd160[1],20); if ( NSPV_addinputs(mtx,satoshis+txfee,64) > 0 ) { - mtx.vout.push_back(CTxOut(nValue,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); hex = NSPV_signt(mtx,txfee,opret); result.push_back(Pair("result","success")); result.push_back(Pair("hex",hex)); From f326cb4ed8819ac9958537bfc005d017af924814 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 01:49:35 -1100 Subject: [PATCH 156/659] syntax --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 6dd7bdf53..fef2021f2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1245,7 +1245,7 @@ int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t else return(belowi); } -int64_t NSPV_addinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) +int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t threshold,above,below; int64_t remains,totalinputs = 0; CTransaction tx; struct NSPV_utxoresp *utxos,*up; utxos = (struct NSPV_utxoresp *)calloc(NSPV_MAXVINS,sizeof(*utxos)); @@ -1374,7 +1374,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al if ( NSPV_addinputs(mtx,satoshis+txfee,64) > 0 ) { mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); - hex = NSPV_signt(mtx,txfee,opret); + hex = NSPV_sign(mtx,txfee,opret); result.push_back(Pair("result","success")); result.push_back(Pair("hex",hex)); // prove all the vins From 6f7f5bb3c63d6e5ff5a367e129f4f692f98a26bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 01:51:19 -1100 Subject: [PATCH 157/659] Syntax --- src/komodo_nSPV.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fef2021f2..597682175 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1296,14 +1296,13 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret) CTransaction vintx; std::string hex; uint256 hashBlock; int64_t change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n; n = mtx.vout.size(); for (i=0; i= totaloutputs+2*txfee ) @@ -1320,7 +1319,7 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret) if ( GetTransaction(mtx.vin[i].prevout.hash,vintx,hashBlock,false) != 0 ) { utxovout = mtx.vin[i].prevout.n; - if ( SignTx(mtx,i,vintx.vout[utxovout].satoshis,vintx.vout[utxovout].scriptPubKey) == 0 ) + if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask); } } @@ -1374,7 +1373,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al if ( NSPV_addinputs(mtx,satoshis+txfee,64) > 0 ) { mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); - hex = NSPV_sign(mtx,txfee,opret); + hex = NSPV_signtx(mtx,txfee,opret); result.push_back(Pair("result","success")); result.push_back(Pair("hex",hex)); // prove all the vins From 56c5c2a6669f7ef4f66c1b730f94dc61db1a16ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 01:53:55 -1100 Subject: [PATCH 158/659] CScript --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 597682175..a1b71017e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1367,7 +1367,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al return(result); } CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - std::vector data,opret; std::string hex; + std::vector data; CScript opret; std::string hex; data.resize(20); memcpy(&data[0],&rmd160[1],20); if ( NSPV_addinputs(mtx,satoshis+txfee,64) > 0 ) From 8b77ffcda918d244d868d55094f5d04a42e1b369 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 01:54:56 -1100 Subject: [PATCH 159/659] Syntax --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a1b71017e..42bff4968 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1320,7 +1320,7 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret) { utxovout = mtx.vin[i].prevout.n; if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) - fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask); + fprintf(stderr,"signing error for vini.%d\n",i); } } return(EncodeHexTx(mtx)); From cb3c65aa4591b75784bd5826748b209fe0ba4cd6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 01:57:09 -1100 Subject: [PATCH 160/659] NSPV_defaultkey --- src/komodo-tx.cpp | 2 ++ src/komodo_nSPV.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 67ac68cd4..807c4fae4 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -52,6 +52,8 @@ uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 return(0); } +CKey *NSPV_defaultkey() { return(0); } + static bool fCreateBlank; static std::map registers; static const int CONTINUE_EXECUTION=-1; diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 42bff4968..a099c1795 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1387,6 +1387,8 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al } } +// polling loop + void komodo_nSPV(CNode *pto) // polling loop from SendMessages { uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); From 74cc7e050fade205bfa2b7f578cde366db17d213 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 01:59:08 -1100 Subject: [PATCH 161/659] +prints --- src/komodo_nSPV.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a099c1795..6b6408b42 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1261,7 +1261,7 @@ int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs) abovei = belowi = -1; if ( NSPV_vinselect(&abovei,&above,&belowi,&below,utxos,n,remains) < 0 ) { - printf("error finding unspent i.%d of %d, %.8f vs %.8f\n",i,n,(double)remains/COIN,(double)total/COIN); + fprintf(stderr,"error finding unspent i.%d of %d, %.8f vs %.8f\n",i,n,(double)remains/COIN,(double)total/COIN); free(utxos); return(0); } @@ -1270,7 +1270,7 @@ int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs) else ind = belowi; if ( ind < 0 ) { - printf("error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,n,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); + fprintf(stderr,"error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,n,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); free(utxos); return(0); } @@ -1280,7 +1280,7 @@ int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs) remains -= up->satoshis; utxos[ind] = utxos[--n]; memset(&utxos[n],0,sizeof(utxos[n])); - //fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); + fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break; } From a82c26fa7d3eeda26d516c9ccb1d3169feeab977 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 02:03:03 -1100 Subject: [PATCH 162/659] +print --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 6b6408b42..340d77d12 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1366,6 +1366,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al result.push_back(Pair("amount",(double)satoshis/COIN)); return(result); } + printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.common.numutxos,(double)NSPV_utxosresult.total/COIN); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); std::vector data; CScript opret; std::string hex; data.resize(20); From f0a715209ef8eccfa7eb4a444bc23f0135eb4509 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 02:04:55 -1100 Subject: [PATCH 163/659] Syntax --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 340d77d12..54d748a5a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1366,7 +1366,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al result.push_back(Pair("amount",(double)satoshis/COIN)); return(result); } - printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.common.numutxos,(double)NSPV_utxosresult.total/COIN); + printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); std::vector data; CScript opret; std::string hex; data.resize(20); From c66229f90925ca19e8804b109c338ef4ae45772a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 02:11:08 -1100 Subject: [PATCH 164/659] NSPV_utxosresult.numutxos --- src/komodo_nSPV.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 54d748a5a..9317dd6e7 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1245,10 +1245,12 @@ int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t else return(belowi); } -int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs) +int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t n) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t threshold,above,below; int64_t remains,totalinputs = 0; CTransaction tx; struct NSPV_utxoresp *utxos,*up; - utxos = (struct NSPV_utxoresp *)calloc(NSPV_MAXVINS,sizeof(*utxos)); + utxos = (struct NSPV_utxoresp *)calloc(n,sizeof(*utxos)); + for (i=0; i NSPV_MAXVINS ) maxinputs = NSPV_MAXVINS; if ( maxinputs > 0 ) @@ -1371,7 +1373,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al std::vector data; CScript opret; std::string hex; data.resize(20); memcpy(&data[0],&rmd160[1],20); - if ( NSPV_addinputs(mtx,satoshis+txfee,64) > 0 ) + if ( NSPV_addinputs(mtx,satoshis+txfee,64,NSPV_utxosresult.utxos,NSPV_utxosresult.numutxos) > 0 ) { mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); hex = NSPV_signtx(mtx,txfee,opret); From c3324c8546bdea6ce26a952d40ebd5560c556c6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 02:12:18 -1100 Subject: [PATCH 165/659] Num --- src/komodo_nSPV.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9317dd6e7..a57dad634 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1245,12 +1245,12 @@ int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t else return(belowi); } -int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t n) +int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t num) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t threshold,above,below; int64_t remains,totalinputs = 0; CTransaction tx; struct NSPV_utxoresp *utxos,*up; utxos = (struct NSPV_utxoresp *)calloc(n,sizeof(*utxos)); - for (i=0; i NSPV_MAXVINS ) maxinputs = NSPV_MAXVINS; if ( maxinputs > 0 ) From fcbd27914ae912c14936f8f93b1c5dc68f9f935c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 02:18:21 -1100 Subject: [PATCH 166/659] +print --- src/komodo_nSPV.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a57dad634..9d0450c0f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1249,14 +1249,18 @@ int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs, { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t threshold,above,below; int64_t remains,totalinputs = 0; CTransaction tx; struct NSPV_utxoresp *utxos,*up; utxos = (struct NSPV_utxoresp *)calloc(n,sizeof(*utxos)); - for (i=0; i NSPV_MAXVINS ) maxinputs = NSPV_MAXVINS; if ( maxinputs > 0 ) threshold = total/maxinputs; else threshold = total; + for (i=0; i threshold ) + utxos[n++] = ptr[i]; + } remains = total; + fprintf(stderr,"n.%d for total %.8f\n",n,(double)total/COIN); for (i=0; i0; i++) { below = above = 0; @@ -1276,6 +1280,7 @@ int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs, free(utxos); return(0); } + fprintf(stderr,"i.%d ind.%d abovei.%d belowi.%d n.%d\n",i,ind,abovei,belowi,n); up = &utxos[ind]; mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); totalinputs += up->satoshis; @@ -1287,6 +1292,7 @@ int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs, break; } free(utxos); + fprintf(stderr,"totalinputs %.8f vs total %.8f\n",(double)totalinputs/COIN,(double)total/COIN); if ( totalinputs >= total ) return(totalinputs); return(0); @@ -1316,6 +1322,7 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret) mtx.vout.push_back(CTxOut(0,opret)); PrecomputedTransactionData txdata(mtx); n = mtx.vin.size(); + fprintf(stderr,"sign inputs %.8f -> outputs %.8f change %.8f\n",(double)totalinputs/COIN,(double)totaloutputs/COIN,(double)change/COIN); for (i=0; i 0 ) { + fprintf(stderr,"vout\n"); mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); + fprintf(stderr,"signtx\n"); hex = NSPV_signtx(mtx,txfee,opret); result.push_back(Pair("result","success")); result.push_back(Pair("hex",hex)); From 7a45609a229de81f1f5dcb615c565a1f755e567e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 02:22:58 -1100 Subject: [PATCH 167/659] Handle single utxo case --- src/cc/CCtx.cpp | 9 +++++++-- src/komodo_nSPV.h | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 7435defbf..5c2fcf10d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -585,8 +585,13 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); totalinputs += up->nValue; remains -= up->nValue; - utxos[ind] = utxos[--n]; - memset(&utxos[n],0,sizeof(utxos[n])); + if ( n > 1 ) + { + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); + } else --n; + //utxos[ind] = utxos[--n]; + //memset(&utxos[n],0,sizeof(utxos[n])); //fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break; diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9d0450c0f..f7fc577d5 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1285,8 +1285,11 @@ int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs, mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); totalinputs += up->satoshis; remains -= up->satoshis; - utxos[ind] = utxos[--n]; - memset(&utxos[n],0,sizeof(utxos[n])); + if ( n > 1 ) + { + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); + } else --n; fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break; From e7a05fc61572edc705c4ac6ec135e48fa76a3d36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 02:26:55 -1100 Subject: [PATCH 168/659] Alloc --- src/cc/CCtx.cpp | 9 ++------- src/komodo_nSPV.h | 9 +++------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 5c2fcf10d..7435defbf 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -585,13 +585,8 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); totalinputs += up->nValue; remains -= up->nValue; - if ( n > 1 ) - { - utxos[ind] = utxos[--n]; - memset(&utxos[n],0,sizeof(utxos[n])); - } else --n; - //utxos[ind] = utxos[--n]; - //memset(&utxos[n],0,sizeof(utxos[n])); + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); //fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break; diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f7fc577d5..01c5b8bab 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1248,7 +1248,7 @@ int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t num) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t threshold,above,below; int64_t remains,totalinputs = 0; CTransaction tx; struct NSPV_utxoresp *utxos,*up; - utxos = (struct NSPV_utxoresp *)calloc(n,sizeof(*utxos)); + utxos = (struct NSPV_utxoresp *)calloc(num,sizeof(*utxos)); if ( maxinputs > NSPV_MAXVINS ) maxinputs = NSPV_MAXVINS; if ( maxinputs > 0 ) @@ -1285,11 +1285,8 @@ int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs, mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); totalinputs += up->satoshis; remains -= up->satoshis; - if ( n > 1 ) - { - utxos[ind] = utxos[--n]; - memset(&utxos[n],0,sizeof(utxos[n])); - } else --n; + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break; From 4d095fce5d93da908a68de7775a0d436f675f46c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 03:25:02 -1100 Subject: [PATCH 169/659] NSPV_gettransaction and split out into 4 files --- src/komodo_nSPV.h | 1067 +---------------------------------- src/komodo_nSPV_fullnode.h | 464 +++++++++++++++ src/komodo_nSPV_superlite.h | 413 ++++++++++++++ src/komodo_nSPV_wallet.h | 277 +++++++++ src/main.cpp | 5 +- 5 files changed, 1160 insertions(+), 1066 deletions(-) create mode 100644 src/komodo_nSPV_fullnode.h create mode 100644 src/komodo_nSPV_superlite.h create mode 100644 src/komodo_nSPV_wallet.h diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 01c5b8bab..91c6ba7f4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -23,6 +23,8 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H +// nSPV defines and struct definitions with serialization and purge functions + #define NSPV_INFO 0x00 #define NSPV_INFORESP 0x01 #define NSPV_UTXOS 0x02 @@ -359,1069 +361,4 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) } } -// on fullnode: -// NSPV_get... functions need to return the exact serialized length, which is the size of the structure minus size of pointers, plus size of allocated data - -#include "notarisationdb.h" - -uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) -{ - uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - memset(&txid,0,sizeof(txid)); - *ntzheightp = 0; - int32_t matchedHeight = ScanNotarisationsDB2(height,symbol,1440,nota); - if ( matchedHeight != 0 ) - { - *ntzheightp = matchedHeight; - txid = nota.first; - } - return(txid); -} - -uint256 NSPV_extract_desttxid(int32_t *heightp,char *symbol,std::vector opret) -{ - uint256 desttxid; int32_t i; - //for (i=0; i<32; i++) - // fprintf(stderr,"%02x",opret[i]); - //fprintf(stderr," blockhash, "); - //for (i=0; i<4; i++) - // fprintf(stderr,"%02x",opret[32+i]); - //fprintf(stderr," height, "); - iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); - //for (i=0; i<32; i++) - // fprintf(stderr,"%02x",opret[36+i]); - //fprintf(stderr," desttxid\n"); - for (i=0; i<32; i++) - ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; - return(desttxid); -} - -int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) -{ - int32_t txidht; Notarisation nota; char *symbol; - symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - memset(txids,0,sizeof(*txids)*2); - memset(desttxids,0,sizeof(*desttxids)*2); - memset(ntzheights,0,sizeof(*ntzheights)*2); - memset(txidhts,0,sizeof(*txidhts)*2); - if ( (txidht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 ) - return(-1); - txids[0] = nota.first; - txidhts[0] = txidht; - desttxids[0] = NSPV_extract_desttxid(&ntzheights[0],symbol,E_MARSHAL(ss << nota.second)); - if ( height != 2668 ) - fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); - if ( ntzheights[0] == height-1 ) // offset the +1 from caller - { - txids[1] = txids[0]; - txidhts[1] = txidhts[0]; - ntzheights[1] = ntzheights[0]; - desttxids[1] = desttxids[0]; - return(0); - } - if ( (txidht= ScanNotarisationsDB2(height,symbol,1440,nota)) != 0 ) - { - txids[1] = nota.first; - txidhts[1] = txidht; - desttxids[1] = NSPV_extract_desttxid(&ntzheights[1],symbol,E_MARSHAL(ss << nota.second)); - } - return(0); -} - -int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint256 desttxid,int32_t ntzheight) -{ - ptr->blockhash = *chainActive[ntzheight]->phashBlock; - ptr->height = ntzheight; - ptr->txidheight = txidht; - ptr->othertxid = desttxid; - ptr->txid = ntztxid; - return(0); -} - -int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) -{ - uint256 txids[2],desttxids[2]; int32_t ntzheights[2],txidhts[2]; - if ( height < chainActive.LastTip()->GetHeight() ) - height++; - if ( komodo_notarized_bracket(txids,txidhts,desttxids,ntzheights,height) == 0 ) - { - if ( ntzheights[0] != 0 ) - { - if ( NSPV_ntzextract(&ptr->prevntz,txids[0],txidhts[0],desttxids[0],ntzheights[0]) < 0 ) - return(-1); - } - if ( ntzheights[1] != 0 ) - { - if ( NSPV_ntzextract(&ptr->nextntz,txids[1],txidhts[1],desttxids[1],ntzheights[1]) < 0 ) - return(-1); - } - } - return(sizeof(*ptr)); -} - -int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) -{ - int32_t prevMoMheight,len = 0; CBlockIndex *pindex; struct NSPV_ntzsresp pair; - if ( (pindex= chainActive.LastTip()) != 0 ) - { - ptr->height = pindex->GetHeight(); - ptr->blockhash = pindex->GetBlockHash(); - if ( NSPV_getntzsresp(&pair,ptr->height-1) < 0 ) - return(-1); - ptr->notarization = pair.prevntz; - return(sizeof(*ptr)); - } else return(-1); -} - -int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check mempool -{ - int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; - std::vector > unspentOutputs; - SetCCunspents(unspentOutputs,coinaddr,false); - maxlen = MAX_BLOCK_SIZE(tipheight) - 512; - maxlen /= sizeof(*ptr->utxos); - strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); - if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 && ptr->numutxos < maxlen ) - { - tipheight = chainActive.LastTip()->GetHeight(); - ptr->nodeheight = tipheight; - ptr->utxos = (struct NSPV_utxoresp *)calloc(ptr->numutxos,sizeof(*ptr->utxos)); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - ptr->utxos[n].txid = it->first.txhash; - ptr->utxos[n].vout = (int32_t)it->first.index; - ptr->utxos[n].satoshis = it->second.satoshis; - ptr->utxos[n].height = it->second.blockHeight; - if ( ASSETCHAINS_SYMBOL[0] == 0 && it->second.satoshis >= 10*COIN ) - { - ptr->utxos[n].extradata = komodo_accrued_interest(&txheight,&locktime,ptr->utxos[n].txid,ptr->utxos[n].vout,ptr->utxos[n].height,ptr->utxos[n].satoshis,tipheight); - interest += ptr->utxos[n].extradata; - } - total += it->second.satoshis; - n++; - } - if ( len < maxlen ) - { - len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos - sizeof(ptr->utxos)); - fprintf(stderr,"getaddressutxos for %s -> n.%d:%d total %.8f interest %.8f len.%d\n",coinaddr,n,ptr->numutxos,dstr(total),dstr(interest),len); - if ( n == ptr->numutxos ) - { - ptr->total = total; - ptr->interest = interest; - return(len); - } - } - } - if ( ptr->utxos != 0 ) - free(ptr->utxos); - memset(ptr,0,sizeof(*ptr)); - return(0); -} - -uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) -{ - CTransaction tx; uint8_t *rawtx = 0; - *txlenp = 0; - { - LOCK(cs_main); - if (!GetTransaction(txid, tx, hashBlock, false)) - return(0); - string strHex = EncodeHexTx(tx); - *txlenp = (int32_t)strHex.size() >> 1; - if ( *txlenp > 0 ) - { - rawtx = (uint8_t *)calloc(1,*txlenp); - decode_hex(rawtx,*txlenp,(char *)strHex.c_str()); - } - } - return(rawtx); -} - -int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) -{ - int32_t flag = 0,len = 0; uint256 hashBlock; CBlock block; CBlockIndex *pindex; - if ( (ptr->tx= NSPV_getrawtx(hashBlock,&ptr->txlen,txid)) == 0 ) - return(-1); - ptr->txid = txid; - ptr->height = height; - if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) - { - BOOST_FOREACH(const CTransaction&tx, block.vtx) - { - if ( tx.GetHash() == txid ) - { - flag = 1; - break; - } - } - if ( flag != 0 ) - { - set setTxids; - CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); - setTxids.insert(txid); - CMerkleBlock mb(block, setTxids); - ssMB << mb; - std::vector proof(ssMB.begin(), ssMB.end()); - ptr->txprooflen = (int32_t)proof.size(); - if ( ptr->txprooflen > 0 ) - { - ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); - memcpy(ptr->txproof,&proof[0],ptr->txprooflen); - } - //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); - return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); - } - } - return(-1); -} - -int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) -{ - CBlockIndex *pindex; - if ( (pindex= komodo_chainactive(height)) != 0 ) - { - hdr->nVersion = pindex->nVersion; - if ( pindex->pprev == 0 ) - return(-1); - hdr->hashPrevBlock = pindex->pprev->GetBlockHash(); - hdr->hashMerkleRoot = pindex->hashMerkleRoot; - hdr->hashFinalSaplingRoot = pindex->hashFinalSaplingRoot; - hdr->nTime = pindex->nTime; - hdr->nBits = pindex->nBits; - hdr->nNonce = pindex->nNonce; - memcpy(hdr->nSolution,&pindex->nSolution[0],sizeof(hdr->nSolution)); - return(sizeof(*hdr)); - } - return(-1); -} - -int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) -{ - int32_t i; uint256 hashBlock; - if ( prevht > nextht || (nextht-prevht) > 1440 ) - { - fprintf(stderr,"illegal prevht.%d nextht.%d\n",prevht,nextht); - return(-1); - } - ptr->common.prevht = prevht; - ptr->common.nextht = nextht; - ptr->common.numhdrs = (nextht - prevht + 1); - ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); - //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); - for (i=0; icommon.numhdrs; i++) - { - if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) - { - fprintf(stderr,"error setting hdr.%d\n",prevht+i); - free(ptr->common.hdrs); - ptr->common.hdrs = 0; - return(-1); - } - } - ptr->prevtxid = NSPV_getnotarization_txid(&ptr->prevtxidht,prevht); - ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid); - ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); - ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid); - //fprintf(stderr,"prevtxlen.%d nexttxlen.%d size %ld -> %ld\n",ptr->prevtxlen,ptr->nexttxlen,sizeof(*ptr),sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); - return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevtxlen + ptr->nexttxlen); -} - -int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) -{ - int32_t len = 0; - ptr->txid = txid; - ptr->vout = vout; - ptr->spentvini = -1; - len = (int32_t)(sizeof(*ptr) - sizeof(ptr->spent.tx) - sizeof(ptr->spent.txproof)); - if ( CCgetspenttxid(ptr->spent.txid,ptr->spentvini,ptr->spent.height,txid,vout) == 0 ) - { - if ( NSPV_gettxproof(&ptr->spent,ptr->spent.txid,ptr->spent.height) > 0 ) - len += ptr->spent.txlen + ptr->spent.txprooflen; - else - { - NSPV_txproof_purge(&ptr->spent); - return(-1); - } - } - return(len); -} - -void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request -{ - int32_t len,slen,ind; std::vector response; uint32_t timestamp = (uint32_t)time(NULL); - if ( (len= request.size()) > 0 ) - { - if ( (ind= request[0]>>1) >= sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes) ) - ind = (int32_t)(sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes)) - 1; - if ( pfrom->prevtimes[ind] > timestamp ) - pfrom->prevtimes[ind] = 0; - if ( request[0] == NSPV_INFO ) // info - { - //fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); - if ( timestamp > pfrom->prevtimes[ind] ) - { - struct NSPV_inforesp I; - memset(&I,0,sizeof(I)); - if ( (slen= NSPV_getinfo(&I)) > 0 ) - { - response.resize(1 + slen); - response[0] = NSPV_INFORESP; - if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) - { - pfrom->PushMessage("nSPV",response); - pfrom->prevtimes[ind] = timestamp; - } - NSPV_inforesp_purge(&I); - } - } - } - else if ( request[0] == NSPV_UTXOS ) - { - //fprintf(stderr,"utxos: %u > %u, ind.%d, len.%d\n",timestamp,pfrom->prevtimes[ind],ind,len); - if ( timestamp > pfrom->prevtimes[ind] ) - { - struct NSPV_utxosresp U; char coinaddr[64]; - if ( len < 64 && request[1] == len-2 ) - { - memcpy(coinaddr,&request[2],request[1]); - coinaddr[request[1]] = 0; - memset(&U,0,sizeof(U)); - if ( (slen= NSPV_getaddressutxos(&U,coinaddr)) > 0 ) - { - response.resize(1 + slen); - response[0] = NSPV_UTXOSRESP; - if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) - { - pfrom->PushMessage("nSPV",response); - pfrom->prevtimes[ind] = timestamp; - } - NSPV_utxosresp_purge(&U); - } - } - } - } - else if ( request[0] == NSPV_NTZS ) - { - if ( timestamp > pfrom->prevtimes[ind] ) - { - struct NSPV_ntzsresp N; int32_t height; - if ( len == 1+sizeof(height) ) - { - iguana_rwnum(0,&request[1],sizeof(height),&height); - memset(&N,0,sizeof(N)); - if ( (slen= NSPV_getntzsresp(&N,height)) > 0 ) - { - response.resize(1 + slen); - response[0] = NSPV_NTZSRESP; - if ( NSPV_rwntzsresp(1,&response[1],&N) == slen ) - { - pfrom->PushMessage("nSPV",response); - pfrom->prevtimes[ind] = timestamp; - } - NSPV_ntzsresp_purge(&N); - } - } - } - } - else if ( request[0] == NSPV_NTZSPROOF ) - { - if ( timestamp > pfrom->prevtimes[ind] ) - { - struct NSPV_ntzsproofresp P; int32_t prevht,nextht; - if ( len == 1+sizeof(prevht)+sizeof(nextht) ) - { - iguana_rwnum(0,&request[1],sizeof(prevht),&prevht); - iguana_rwnum(0,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); - if ( prevht != 0 && nextht != 0 && nextht >= prevht ) - { - memset(&P,0,sizeof(P)); - if ( (slen= NSPV_getntzsproofresp(&P,prevht,nextht)) > 0 ) - { - response.resize(1 + slen); - response[0] = NSPV_NTZSPROOFRESP; - P.common.numhdrs = (nextht - prevht + 1); - if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) - { - pfrom->PushMessage("nSPV",response); - pfrom->prevtimes[ind] = timestamp; - } - NSPV_ntzsproofresp_purge(&P); - } - } - } - } - } - else if ( request[0] == NSPV_TXPROOF ) - { - if ( timestamp > pfrom->prevtimes[ind] ) - { - struct NSPV_txproof P; uint256 txid; int32_t height; - if ( len == 1+sizeof(txid)+sizeof(height) ) - { - iguana_rwnum(0,&request[1],sizeof(height),&height); - iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); - //fprintf(stderr,"got txid ht.%d\n",txid.GetHex().c_str(),height); - memset(&P,0,sizeof(P)); - if ( (slen= NSPV_gettxproof(&P,txid,height)) > 0 ) - { - response.resize(1 + slen); - response[0] = NSPV_TXPROOFRESP; - if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) - { - pfrom->PushMessage("nSPV",response); - pfrom->prevtimes[ind] = timestamp; - } - NSPV_txproof_purge(&P); - } - } - } - } - else if ( request[0] == NSPV_SPENTINFO ) - { - if ( timestamp > pfrom->prevtimes[ind] ) - { - struct NSPV_spentinfo S; int32_t vout; uint256 txid; - if ( len == 1+sizeof(txid)+sizeof(vout) ) - { - iguana_rwnum(0,&request[1],sizeof(vout),&vout); - iguana_rwbignum(0,&request[1+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); - memset(&S,0,sizeof(S)); - if ( (slen= NSPV_getspentinfo(&S,txid,vout)) > 0 ) - { - response.resize(1 + slen); - response[0] = NSPV_SPENTINFORESP; - if ( NSPV_rwspentinfo(1,&response[1],&S) == slen ) - { - pfrom->PushMessage("nSPV",response); - pfrom->prevtimes[ind] = timestamp; - } - NSPV_spentinfo_purge(&S); - } - } - } - } - } -} - -// nSPV client. VERY simplistic "single threaded" networking model. for production GUI best to multithread, etc. -#define NSPV_POLLITERS 15 -#define NSPV_POLLMICROS 100000 -#define NSPV_MAXVINS 64 - -CAmount AmountFromValue(const UniValue& value); -int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); - -uint32_t NSPV_lastinfo,NSPV_logintime; -char NSPV_wifstr[64],NSPV_pubkeystr[67]; -std::string NSPV_address; -CKey NSPV_key; -struct NSPV_inforesp NSPV_inforesult; -struct NSPV_utxosresp NSPV_utxosresult; -struct NSPV_spentinfo NSPV_spentresult; -struct NSPV_ntzsresp NSPV_ntzsresult; -struct NSPV_ntzsproofresp NSPV_ntzsproofresult; -struct NSPV_txproof NSPV_txproofresult; -struct NSPV_utxo *NSPV_utxos; - -CKey *NSPV_defaultkey() -{ - return(&NSPV_key); -} - -CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) -{ - int32_t flag = 0; uint32_t timestamp = (uint32_t)time(NULL); - if ( pnode == 0 ) - { - LOCK(cs_vNodes); - BOOST_FOREACH(CNode *ptr,vNodes) - { - if ( ptr->prevtimes[ind] > timestamp ) - ptr->prevtimes[ind] = 0; - if ( ptr->hSocket == INVALID_SOCKET ) - continue; - if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) - { - flag = 1; - pnode = ptr; - break; - } //else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); - } - } else flag = 1; - if ( pnode != 0 ) - { - std::vector request; - request.resize(len); - memcpy(&request[0],msg,len); - //fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); - pnode->PushMessage("getnSPV",request); - pnode->prevtimes[ind] = timestamp; - return(pnode); - } else fprintf(stderr,"no pnodes\n"); - return(0); -} - -UniValue NSPV_txproof_json(struct NSPV_txproof *ptr) -{ - UniValue result(UniValue::VOBJ); - result.push_back(Pair("txid",ptr->txid.GetHex())); - result.push_back(Pair("height",(int64_t)ptr->height)); - result.push_back(Pair("txlen",(int64_t)ptr->txlen)); - result.push_back(Pair("txprooflen",(int64_t)ptr->txprooflen)); - return(result); -} - -UniValue NSPV_spentinfo_json(struct NSPV_spentinfo *ptr) -{ - UniValue result(UniValue::VOBJ); - result.push_back(Pair("result","success")); - result.push_back(Pair("txid",ptr->txid.GetHex())); - result.push_back(Pair("vout",(int64_t)ptr->vout)); - result.push_back(Pair("spentheight",(int64_t)ptr->spent.height)); - result.push_back(Pair("spenttxid",ptr->spent.txid.GetHex())); - result.push_back(Pair("spentvini",(int64_t)ptr->spentvini)); - result.push_back(Pair("spenttxlen",(int64_t)ptr->spent.txlen)); - result.push_back(Pair("spenttxprooflen",(int64_t)ptr->spent.txprooflen)); - return(result); -} - -UniValue NSPV_ntz_json(struct NSPV_ntz *ptr) -{ - UniValue result(UniValue::VOBJ); - result.push_back(Pair("notarized_height",(int64_t)ptr->height)); - result.push_back(Pair("notarized_blockhash",ptr->blockhash.GetHex())); - result.push_back(Pair("notarization_txid",ptr->txid.GetHex())); - result.push_back(Pair("notarization_txidheight",(int64_t)ptr->txidheight)); - result.push_back(Pair("notarization_desttxid",ptr->othertxid.GetHex())); - return(result); -} - -UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr) -{ - UniValue result(UniValue::VOBJ); - result.push_back(Pair("result","success")); - result.push_back(Pair("height",(int64_t)ptr->height)); - result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); - result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); - return(result); -} - -UniValue NSPV_utxoresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) -{ - UniValue array(UniValue::VARR); int32_t i; - for (i=0; iutxos,ptr->numutxos))); - result.push_back(Pair("address",ptr->coinaddr)); - result.push_back(Pair("height",(int64_t)ptr->nodeheight)); - result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); - result.push_back(Pair("balance",(double)ptr->total/COIN)); - if ( ASSETCHAINS_SYMBOL[0] == 0 ) - result.push_back(Pair("interest",(double)ptr->interest/COIN)); - return(result); -} - -UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr) -{ - UniValue result(UniValue::VOBJ); - result.push_back(Pair("result","success")); - result.push_back(Pair("prev",NSPV_ntz_json(&ptr->prevntz))); - result.push_back(Pair("next",NSPV_ntz_json(&ptr->nextntz))); - return(result); -} - -UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs) -{ - UniValue array(UniValue::VARR); int32_t i; - for (i=0; icommon.prevht)); - result.push_back(Pair("nextht",(int64_t)ptr->common.nextht)); - result.push_back(Pair("prevtxid",ptr->prevtxid.GetHex())); - result.push_back(Pair("prevtxidht",(int64_t)ptr->prevtxidht)); - result.push_back(Pair("prevtxlen",(int64_t)ptr->prevtxlen)); - result.push_back(Pair("nexttxid",ptr->nexttxid.GetHex())); - result.push_back(Pair("nexttxidht",(int64_t)ptr->nexttxidht)); - result.push_back(Pair("nexttxlen",(int64_t)ptr->prevtxlen)); - result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); - result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs))); - return(result); -} - -UniValue NSPV_login(char *wifstr) -{ - UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0; - len = bitcoin_base58decode(data,wifstr); - if ( strlen(wifstr) < 64 && (len == 38 && data[len-5] == 1) || (len == 37 && data[len-5] != 1) ) - valid = 1; - if ( valid == 0 || data[0] != 188 ) - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","invalid wif")); - result.push_back(Pair("len",(int64_t)len)); - result.push_back(Pair("prefix",(int64_t)data[0])); - return(result); - } - memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); - strncpy(NSPV_wifstr,wifstr,sizeof(NSPV_wifstr)-1); - NSPV_logintime = (uint32_t)time(NULL); - result.push_back(Pair("result","success")); - result.push_back(Pair("status","wif will expire in 60 seconds")); - NSPV_key = DecodeSecret(wifstr); - CPubKey pubkey = NSPV_key.GetPubKey(); - CKeyID vchAddress = pubkey.GetID(); - NSPV_address = EncodeDestination(vchAddress); - result.push_back(Pair("address",NSPV_address)); - result.push_back(Pair("pubkey",HexStr(pubkey))); - strcpy(NSPV_pubkeystr,HexStr(pubkey).c_str()); - result.push_back(Pair("wifprefix",(int64_t)data[0])); - result.push_back(Pair("compressed",(int64_t)(data[len-5] == 1))); - memset(data,0,sizeof(data)); - return(result); -} - -UniValue NSPV_getinfo_json() -{ - uint8_t msg[64]; int32_t i,iters,len = 0; struct NSPV_inforesp I; - NSPV_inforesp_purge(&NSPV_inforesult); - msg[len++] = NSPV_INFO; - for (iters=0; iters<3; iters++) - { - //fprintf(stderr,"issue getinfo\n"); - if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) - { - for (i=0; i>1); - } - slen = (int32_t)strlen(coinaddr); - msg[len++] = NSPV_UTXOS; - msg[len++] = slen; - memcpy(&msg[len],coinaddr,slen), len += slen; - msg[len] = 0; - if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) - { - for (i=0; i= NSPV_inforesult.height ) - return(NSPV_utxosresp_json(&NSPV_utxosresult)); - } - } - result.push_back(Pair("result","error")); - result.push_back(Pair("error","no utxos result")); - return(result); -} - -UniValue NSPV_notarizations(int32_t height) -{ - uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsresp N; - if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) - return(NSPV_ntzs_json(&NSPV_ntzsresult)); - msg[len++] = NSPV_NTZS; - len += iguana_rwnum(1,&msg[len],sizeof(height),&height); - if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) - { - for (i=0; i= height ) - return(NSPV_ntzs_json(&NSPV_ntzsresult)); - } - } - memset(&N,0,sizeof(N)); - return(NSPV_ntzs_json(&N)); -} - -UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) -{ - uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsproofresp H; - if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) - return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); - msg[len++] = NSPV_NTZSPROOF; - len += iguana_rwnum(1,&msg[len],sizeof(prevheight),&prevheight); - len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight); - if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) - { - for (i=0; i= nextheight ) - return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); - } - } - memset(&H,0,sizeof(H)); - return(NSPV_ntzsproof_json(&H)); -} - -UniValue NSPV_txproof(uint256 txid,int32_t height) -{ - uint8_t msg[64]; int32_t i,len = 0; struct NSPV_txproof P; - if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) - return(NSPV_txproof_json(&NSPV_txproofresult)); - msg[len++] = NSPV_TXPROOF; - len += iguana_rwnum(1,&msg[len],sizeof(height),&height); - len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); - //fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height); - if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) - { - for (i=0; i>1) != 0 ) - { - for (i=0; i response) // received a response -{ - int32_t len; uint32_t timestamp = (uint32_t)time(NULL); - if ( (len= response.size()) > 0 ) - { - switch ( response[0] ) - { - case NSPV_INFORESP: - NSPV_inforesp_purge(&NSPV_inforesult); - NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); - //fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status - break; - case NSPV_UTXOSRESP: - NSPV_utxosresp_purge(&NSPV_utxosresult); - NSPV_rwutxosresp(0,&response[1],&NSPV_utxosresult); - fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos list - break; - case NSPV_NTZSRESP: - NSPV_ntzsresp_purge(&NSPV_ntzsresult); - NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); - fprintf(stderr,"got ntzs response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] - break; - case NSPV_NTZSPROOFRESP: - NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); - NSPV_rwntzsproofresp(0,&response[1],&NSPV_ntzsproofresult); - fprintf(stderr,"got ntzproof response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsproofresult.common.prevht,NSPV_ntzsproofresult.common.nextht); // update utxos[i] - break; - case NSPV_TXPROOFRESP: - NSPV_txproof_purge(&NSPV_txproofresult); - NSPV_rwtxproof(0,&response[1],&NSPV_txproofresult); - fprintf(stderr,"got txproof response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] - break; - case NSPV_SPENTINFORESP: - - NSPV_spentinfo_purge(&NSPV_spentresult); - NSPV_rwspentinfo(0,&response[1],&NSPV_spentresult); - fprintf(stderr,"got spentinfo response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] - break; - default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); - break; - } - } -} - -// nSPV wallet - -int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) -{ - int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; - abovei = belowi = -1; - for (above=below=i=0; i value ) - { - gap = (atx_value - value); - if ( above == 0 || gap < above ) - { - above = gap; - abovei = i; - } - } - else - { - gap = (value - atx_value); - if ( below == 0 || gap < below ) - { - below = gap; - belowi = i; - } - } - //printf("value %.8f gap %.8f abovei.%d %.8f belowi.%d %.8f\n",dstr(value),dstr(gap),abovei,dstr(above),belowi,dstr(below)); - } - *aboveip = abovei; - *abovep = above; - *belowip = belowi; - *belowp = below; - //printf("above.%d below.%d\n",abovei,belowi); - if ( abovei >= 0 && belowi >= 0 ) - { - if ( above < (below >> 1) ) - return(abovei); - else return(belowi); - } - else if ( abovei >= 0 ) - return(abovei); - else return(belowi); -} - -int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t num) -{ - int32_t abovei,belowi,ind,vout,i,n = 0; int64_t threshold,above,below; int64_t remains,totalinputs = 0; CTransaction tx; struct NSPV_utxoresp *utxos,*up; - utxos = (struct NSPV_utxoresp *)calloc(num,sizeof(*utxos)); - if ( maxinputs > NSPV_MAXVINS ) - maxinputs = NSPV_MAXVINS; - if ( maxinputs > 0 ) - threshold = total/maxinputs; - else threshold = total; - for (i=0; i threshold ) - utxos[n++] = ptr[i]; - } - remains = total; - fprintf(stderr,"n.%d for total %.8f\n",n,(double)total/COIN); - for (i=0; i0; i++) - { - below = above = 0; - abovei = belowi = -1; - if ( NSPV_vinselect(&abovei,&above,&belowi,&below,utxos,n,remains) < 0 ) - { - fprintf(stderr,"error finding unspent i.%d of %d, %.8f vs %.8f\n",i,n,(double)remains/COIN,(double)total/COIN); - free(utxos); - return(0); - } - if ( belowi < 0 || abovei >= 0 ) - ind = abovei; - else ind = belowi; - if ( ind < 0 ) - { - fprintf(stderr,"error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,n,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); - free(utxos); - return(0); - } - fprintf(stderr,"i.%d ind.%d abovei.%d belowi.%d n.%d\n",i,ind,abovei,belowi,n); - up = &utxos[ind]; - mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); - totalinputs += up->satoshis; - remains -= up->satoshis; - utxos[ind] = utxos[--n]; - memset(&utxos[n],0,sizeof(utxos[n])); - fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); - if ( totalinputs >= total || (i+1) >= maxinputs ) - break; - } - free(utxos); - fprintf(stderr,"totalinputs %.8f vs total %.8f\n",(double)totalinputs/COIN,(double)total/COIN); - if ( totalinputs >= total ) - return(totalinputs); - return(0); -} - -std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret) -{ - auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - CTransaction vintx; std::string hex; uint256 hashBlock; int64_t change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n; - n = mtx.vout.size(); - for (i=0; i= totaloutputs+2*txfee ) - { - change = totalinputs - (totaloutputs+txfee); - mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(NSPV_pubkeystr) << OP_CHECKSIG)); - } - if ( opret.size() > 0 ) - mtx.vout.push_back(CTxOut(0,opret)); - PrecomputedTransactionData txdata(mtx); - n = mtx.vin.size(); - fprintf(stderr,"sign inputs %.8f -> outputs %.8f change %.8f\n",(double)totalinputs/COIN,(double)totaloutputs/COIN,(double)change/COIN); - for (i=0; i data; CScript opret; std::string hex; - data.resize(20); - memcpy(&data[0],&rmd160[1],20); - if ( NSPV_addinputs(mtx,satoshis+txfee,64,NSPV_utxosresult.utxos,NSPV_utxosresult.numutxos) > 0 ) - { - fprintf(stderr,"vout\n"); - mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); - fprintf(stderr,"signtx\n"); - hex = NSPV_signtx(mtx,txfee,opret); - result.push_back(Pair("result","success")); - result.push_back(Pair("hex",hex)); - // prove all the vins - return(result); - } - else - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","couldnt create tx")); - return(result); - } -} - -// polling loop - -void komodo_nSPV(CNode *pto) // polling loop from SendMessages -{ - uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); - if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+60 ) - { - fprintf(stderr,"scrub wif from NSPV memory\n"); - memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); - memset(&NSPV_key,0,sizeof(NSPV_key)); - NSPV_logintime = 0; - } - if ( (pto->nServices & NODE_NSPV) == 0 ) - return; - if ( KOMODO_NSPV != 0 ) - { - if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) - { - len = 0; - msg[len++] = NSPV_INFO; - NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); - } - } -} - #endif // KOMODO_NSPV_H diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h new file mode 100644 index 000000000..f493512a6 --- /dev/null +++ b/src/komodo_nSPV_fullnode.h @@ -0,0 +1,464 @@ + +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef KOMODO_NSPVFULLNODE_H +#define KOMODO_NSPVFULLNODE_H + +// on fullnode: +// NSPV_get... functions need to return the exact serialized length, which is the size of the structure minus size of pointers, plus size of allocated data + +#include "notarisationdb.h" + +uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) +{ + uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; + memset(&txid,0,sizeof(txid)); + *ntzheightp = 0; + int32_t matchedHeight = ScanNotarisationsDB2(height,symbol,1440,nota); + if ( matchedHeight != 0 ) + { + *ntzheightp = matchedHeight; + txid = nota.first; + } + return(txid); +} + +uint256 NSPV_extract_desttxid(int32_t *heightp,char *symbol,std::vector opret) +{ + uint256 desttxid; int32_t i; + //for (i=0; i<32; i++) + // fprintf(stderr,"%02x",opret[i]); + //fprintf(stderr," blockhash, "); + //for (i=0; i<4; i++) + // fprintf(stderr,"%02x",opret[32+i]); + //fprintf(stderr," height, "); + iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); + //for (i=0; i<32; i++) + // fprintf(stderr,"%02x",opret[36+i]); + //fprintf(stderr," desttxid\n"); + for (i=0; i<32; i++) + ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; + return(desttxid); +} + +int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) +{ + int32_t txidht; Notarisation nota; char *symbol; + symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; + memset(txids,0,sizeof(*txids)*2); + memset(desttxids,0,sizeof(*desttxids)*2); + memset(ntzheights,0,sizeof(*ntzheights)*2); + memset(txidhts,0,sizeof(*txidhts)*2); + if ( (txidht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 ) + return(-1); + txids[0] = nota.first; + txidhts[0] = txidht; + desttxids[0] = NSPV_extract_desttxid(&ntzheights[0],symbol,E_MARSHAL(ss << nota.second)); + if ( height != 2668 ) + fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); + if ( ntzheights[0] == height-1 ) // offset the +1 from caller + { + txids[1] = txids[0]; + txidhts[1] = txidhts[0]; + ntzheights[1] = ntzheights[0]; + desttxids[1] = desttxids[0]; + return(0); + } + if ( (txidht= ScanNotarisationsDB2(height,symbol,1440,nota)) != 0 ) + { + txids[1] = nota.first; + txidhts[1] = txidht; + desttxids[1] = NSPV_extract_desttxid(&ntzheights[1],symbol,E_MARSHAL(ss << nota.second)); + } + return(0); +} + +int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint256 desttxid,int32_t ntzheight) +{ + ptr->blockhash = *chainActive[ntzheight]->phashBlock; + ptr->height = ntzheight; + ptr->txidheight = txidht; + ptr->othertxid = desttxid; + ptr->txid = ntztxid; + return(0); +} + +int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) +{ + uint256 txids[2],desttxids[2]; int32_t ntzheights[2],txidhts[2]; + if ( height < chainActive.LastTip()->GetHeight() ) + height++; + if ( komodo_notarized_bracket(txids,txidhts,desttxids,ntzheights,height) == 0 ) + { + if ( ntzheights[0] != 0 ) + { + if ( NSPV_ntzextract(&ptr->prevntz,txids[0],txidhts[0],desttxids[0],ntzheights[0]) < 0 ) + return(-1); + } + if ( ntzheights[1] != 0 ) + { + if ( NSPV_ntzextract(&ptr->nextntz,txids[1],txidhts[1],desttxids[1],ntzheights[1]) < 0 ) + return(-1); + } + } + return(sizeof(*ptr)); +} + +int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) +{ + int32_t prevMoMheight,len = 0; CBlockIndex *pindex; struct NSPV_ntzsresp pair; + if ( (pindex= chainActive.LastTip()) != 0 ) + { + ptr->height = pindex->GetHeight(); + ptr->blockhash = pindex->GetBlockHash(); + if ( NSPV_getntzsresp(&pair,ptr->height-1) < 0 ) + return(-1); + ptr->notarization = pair.prevntz; + return(sizeof(*ptr)); + } else return(-1); +} + +int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check mempool +{ + int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; + std::vector > unspentOutputs; + SetCCunspents(unspentOutputs,coinaddr,false); + maxlen = MAX_BLOCK_SIZE(tipheight) - 512; + maxlen /= sizeof(*ptr->utxos); + strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); + if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 && ptr->numutxos < maxlen ) + { + tipheight = chainActive.LastTip()->GetHeight(); + ptr->nodeheight = tipheight; + ptr->utxos = (struct NSPV_utxoresp *)calloc(ptr->numutxos,sizeof(*ptr->utxos)); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + ptr->utxos[n].txid = it->first.txhash; + ptr->utxos[n].vout = (int32_t)it->first.index; + ptr->utxos[n].satoshis = it->second.satoshis; + ptr->utxos[n].height = it->second.blockHeight; + if ( ASSETCHAINS_SYMBOL[0] == 0 && it->second.satoshis >= 10*COIN ) + { + ptr->utxos[n].extradata = komodo_accrued_interest(&txheight,&locktime,ptr->utxos[n].txid,ptr->utxos[n].vout,ptr->utxos[n].height,ptr->utxos[n].satoshis,tipheight); + interest += ptr->utxos[n].extradata; + } + total += it->second.satoshis; + n++; + } + if ( len < maxlen ) + { + len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos - sizeof(ptr->utxos)); + fprintf(stderr,"getaddressutxos for %s -> n.%d:%d total %.8f interest %.8f len.%d\n",coinaddr,n,ptr->numutxos,dstr(total),dstr(interest),len); + if ( n == ptr->numutxos ) + { + ptr->total = total; + ptr->interest = interest; + return(len); + } + } + } + if ( ptr->utxos != 0 ) + free(ptr->utxos); + memset(ptr,0,sizeof(*ptr)); + return(0); +} + +uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) +{ + CTransaction tx; uint8_t *rawtx = 0; + *txlenp = 0; + { + LOCK(cs_main); + if (!GetTransaction(txid, tx, hashBlock, false)) + return(0); + string strHex = EncodeHexTx(tx); + *txlenp = (int32_t)strHex.size() >> 1; + if ( *txlenp > 0 ) + { + rawtx = (uint8_t *)calloc(1,*txlenp); + decode_hex(rawtx,*txlenp,(char *)strHex.c_str()); + } + } + return(rawtx); +} + +int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) +{ + int32_t flag = 0,len = 0; uint256 hashBlock; CBlock block; CBlockIndex *pindex; + if ( (ptr->tx= NSPV_getrawtx(hashBlock,&ptr->txlen,txid)) == 0 ) + return(-1); + ptr->txid = txid; + ptr->height = height; + if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) + { + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + if ( tx.GetHash() == txid ) + { + flag = 1; + break; + } + } + if ( flag != 0 ) + { + set setTxids; + CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); + setTxids.insert(txid); + CMerkleBlock mb(block, setTxids); + ssMB << mb; + std::vector proof(ssMB.begin(), ssMB.end()); + ptr->txprooflen = (int32_t)proof.size(); + if ( ptr->txprooflen > 0 ) + { + ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); + memcpy(ptr->txproof,&proof[0],ptr->txprooflen); + } + //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); + return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); + } + } + return(-1); +} + +int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) +{ + CBlockIndex *pindex; + if ( (pindex= komodo_chainactive(height)) != 0 ) + { + hdr->nVersion = pindex->nVersion; + if ( pindex->pprev == 0 ) + return(-1); + hdr->hashPrevBlock = pindex->pprev->GetBlockHash(); + hdr->hashMerkleRoot = pindex->hashMerkleRoot; + hdr->hashFinalSaplingRoot = pindex->hashFinalSaplingRoot; + hdr->nTime = pindex->nTime; + hdr->nBits = pindex->nBits; + hdr->nNonce = pindex->nNonce; + memcpy(hdr->nSolution,&pindex->nSolution[0],sizeof(hdr->nSolution)); + return(sizeof(*hdr)); + } + return(-1); +} + +int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) +{ + int32_t i; uint256 hashBlock; + if ( prevht > nextht || (nextht-prevht) > 1440 ) + { + fprintf(stderr,"illegal prevht.%d nextht.%d\n",prevht,nextht); + return(-1); + } + ptr->common.prevht = prevht; + ptr->common.nextht = nextht; + ptr->common.numhdrs = (nextht - prevht + 1); + ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); + //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); + for (i=0; icommon.numhdrs; i++) + { + if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) + { + fprintf(stderr,"error setting hdr.%d\n",prevht+i); + free(ptr->common.hdrs); + ptr->common.hdrs = 0; + return(-1); + } + } + ptr->prevtxid = NSPV_getnotarization_txid(&ptr->prevtxidht,prevht); + ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid); + ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); + ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid); + //fprintf(stderr,"prevtxlen.%d nexttxlen.%d size %ld -> %ld\n",ptr->prevtxlen,ptr->nexttxlen,sizeof(*ptr),sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); + return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevtxlen + ptr->nexttxlen); +} + +int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) +{ + int32_t len = 0; + ptr->txid = txid; + ptr->vout = vout; + ptr->spentvini = -1; + len = (int32_t)(sizeof(*ptr) - sizeof(ptr->spent.tx) - sizeof(ptr->spent.txproof)); + if ( CCgetspenttxid(ptr->spent.txid,ptr->spentvini,ptr->spent.height,txid,vout) == 0 ) + { + if ( NSPV_gettxproof(&ptr->spent,ptr->spent.txid,ptr->spent.height) > 0 ) + len += ptr->spent.txlen + ptr->spent.txprooflen; + else + { + NSPV_txproof_purge(&ptr->spent); + return(-1); + } + } + return(len); +} + +void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request +{ + int32_t len,slen,ind; std::vector response; uint32_t timestamp = (uint32_t)time(NULL); + if ( (len= request.size()) > 0 ) + { + if ( (ind= request[0]>>1) >= sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes) ) + ind = (int32_t)(sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes)) - 1; + if ( pfrom->prevtimes[ind] > timestamp ) + pfrom->prevtimes[ind] = 0; + if ( request[0] == NSPV_INFO ) // info + { + //fprintf(stderr,"check info %u vs %u, ind.%d\n",timestamp,pfrom->prevtimes[ind],ind); + if ( timestamp > pfrom->prevtimes[ind] ) + { + struct NSPV_inforesp I; + memset(&I,0,sizeof(I)); + if ( (slen= NSPV_getinfo(&I)) > 0 ) + { + response.resize(1 + slen); + response[0] = NSPV_INFORESP; + if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_inforesp_purge(&I); + } + } + } + else if ( request[0] == NSPV_UTXOS ) + { + //fprintf(stderr,"utxos: %u > %u, ind.%d, len.%d\n",timestamp,pfrom->prevtimes[ind],ind,len); + if ( timestamp > pfrom->prevtimes[ind] ) + { + struct NSPV_utxosresp U; char coinaddr[64]; + if ( len < 64 && request[1] == len-2 ) + { + memcpy(coinaddr,&request[2],request[1]); + coinaddr[request[1]] = 0; + memset(&U,0,sizeof(U)); + if ( (slen= NSPV_getaddressutxos(&U,coinaddr)) > 0 ) + { + response.resize(1 + slen); + response[0] = NSPV_UTXOSRESP; + if ( NSPV_rwutxosresp(1,&response[1],&U) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_utxosresp_purge(&U); + } + } + } + } + else if ( request[0] == NSPV_NTZS ) + { + if ( timestamp > pfrom->prevtimes[ind] ) + { + struct NSPV_ntzsresp N; int32_t height; + if ( len == 1+sizeof(height) ) + { + iguana_rwnum(0,&request[1],sizeof(height),&height); + memset(&N,0,sizeof(N)); + if ( (slen= NSPV_getntzsresp(&N,height)) > 0 ) + { + response.resize(1 + slen); + response[0] = NSPV_NTZSRESP; + if ( NSPV_rwntzsresp(1,&response[1],&N) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_ntzsresp_purge(&N); + } + } + } + } + else if ( request[0] == NSPV_NTZSPROOF ) + { + if ( timestamp > pfrom->prevtimes[ind] ) + { + struct NSPV_ntzsproofresp P; int32_t prevht,nextht; + if ( len == 1+sizeof(prevht)+sizeof(nextht) ) + { + iguana_rwnum(0,&request[1],sizeof(prevht),&prevht); + iguana_rwnum(0,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); + if ( prevht != 0 && nextht != 0 && nextht >= prevht ) + { + memset(&P,0,sizeof(P)); + if ( (slen= NSPV_getntzsproofresp(&P,prevht,nextht)) > 0 ) + { + response.resize(1 + slen); + response[0] = NSPV_NTZSPROOFRESP; + P.common.numhdrs = (nextht - prevht + 1); + if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_ntzsproofresp_purge(&P); + } + } + } + } + } + else if ( request[0] == NSPV_TXPROOF ) + { + if ( timestamp > pfrom->prevtimes[ind] ) + { + struct NSPV_txproof P; uint256 txid; int32_t height; + if ( len == 1+sizeof(txid)+sizeof(height) ) + { + iguana_rwnum(0,&request[1],sizeof(height),&height); + iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); + //fprintf(stderr,"got txid ht.%d\n",txid.GetHex().c_str(),height); + memset(&P,0,sizeof(P)); + if ( (slen= NSPV_gettxproof(&P,txid,height)) > 0 ) + { + response.resize(1 + slen); + response[0] = NSPV_TXPROOFRESP; + if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_txproof_purge(&P); + } + } + } + } + else if ( request[0] == NSPV_SPENTINFO ) + { + if ( timestamp > pfrom->prevtimes[ind] ) + { + struct NSPV_spentinfo S; int32_t vout; uint256 txid; + if ( len == 1+sizeof(txid)+sizeof(vout) ) + { + iguana_rwnum(0,&request[1],sizeof(vout),&vout); + iguana_rwbignum(0,&request[1+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); + memset(&S,0,sizeof(S)); + if ( (slen= NSPV_getspentinfo(&S,txid,vout)) > 0 ) + { + response.resize(1 + slen); + response[0] = NSPV_SPENTINFORESP; + if ( NSPV_rwspentinfo(1,&response[1],&S) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_spentinfo_purge(&S); + } + } + } + } + } +} + +#endif // KOMODO_NSPVFULLNODE_H diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h new file mode 100644 index 000000000..aeca64a9d --- /dev/null +++ b/src/komodo_nSPV_superlite.h @@ -0,0 +1,413 @@ + +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef KOMODO_NSPVSUPERLITE_H +#define KOMODO_NSPVSUPERLITE_H + +// nSPV client. VERY simplistic "single threaded" networking model. for production GUI best to multithread, etc. +// no caching, no optimizations, no reducing the number of ntzsproofs needed by detecting overlaps, etc. +// advantage is that it is simpler to implement and understand to create a design for a more performant version + +#define NSPV_POLLITERS 15 +#define NSPV_POLLMICROS 100000 +#define NSPV_MAXVINS 64 + +CAmount AmountFromValue(const UniValue& value); +int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); + +uint32_t NSPV_lastinfo,NSPV_logintime; +char NSPV_wifstr[64],NSPV_pubkeystr[67]; +std::string NSPV_address; +CKey NSPV_key; +struct NSPV_inforesp NSPV_inforesult; +struct NSPV_utxosresp NSPV_utxosresult; +struct NSPV_spentinfo NSPV_spentresult; +struct NSPV_ntzsresp NSPV_ntzsresult; +struct NSPV_ntzsproofresp NSPV_ntzsproofresult; +struct NSPV_txproof NSPV_txproofresult; +struct NSPV_utxo *NSPV_utxos; + +CKey *NSPV_defaultkey() +{ + return(&NSPV_key); +} + +CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) +{ + int32_t flag = 0; uint32_t timestamp = (uint32_t)time(NULL); + if ( pnode == 0 ) + { + LOCK(cs_vNodes); + BOOST_FOREACH(CNode *ptr,vNodes) + { + if ( ptr->prevtimes[ind] > timestamp ) + ptr->prevtimes[ind] = 0; + if ( ptr->hSocket == INVALID_SOCKET ) + continue; + if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) + { + flag = 1; + pnode = ptr; + break; + } //else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); + } + } else flag = 1; + if ( pnode != 0 ) + { + std::vector request; + request.resize(len); + memcpy(&request[0],msg,len); + //fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); + pnode->PushMessage("getnSPV",request); + pnode->prevtimes[ind] = timestamp; + return(pnode); + } else fprintf(stderr,"no pnodes\n"); + return(0); +} + +UniValue NSPV_txproof_json(struct NSPV_txproof *ptr) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("txid",ptr->txid.GetHex())); + result.push_back(Pair("height",(int64_t)ptr->height)); + result.push_back(Pair("txlen",(int64_t)ptr->txlen)); + result.push_back(Pair("txprooflen",(int64_t)ptr->txprooflen)); + return(result); +} + +UniValue NSPV_spentinfo_json(struct NSPV_spentinfo *ptr) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + result.push_back(Pair("txid",ptr->txid.GetHex())); + result.push_back(Pair("vout",(int64_t)ptr->vout)); + result.push_back(Pair("spentheight",(int64_t)ptr->spent.height)); + result.push_back(Pair("spenttxid",ptr->spent.txid.GetHex())); + result.push_back(Pair("spentvini",(int64_t)ptr->spentvini)); + result.push_back(Pair("spenttxlen",(int64_t)ptr->spent.txlen)); + result.push_back(Pair("spenttxprooflen",(int64_t)ptr->spent.txprooflen)); + return(result); +} + +UniValue NSPV_ntz_json(struct NSPV_ntz *ptr) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("notarized_height",(int64_t)ptr->height)); + result.push_back(Pair("notarized_blockhash",ptr->blockhash.GetHex())); + result.push_back(Pair("notarization_txid",ptr->txid.GetHex())); + result.push_back(Pair("notarization_txidheight",(int64_t)ptr->txidheight)); + result.push_back(Pair("notarization_desttxid",ptr->othertxid.GetHex())); + return(result); +} + +UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + result.push_back(Pair("height",(int64_t)ptr->height)); + result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); + result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); + return(result); +} + +UniValue NSPV_utxoresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) +{ + UniValue array(UniValue::VARR); int32_t i; + for (i=0; iutxos,ptr->numutxos))); + result.push_back(Pair("address",ptr->coinaddr)); + result.push_back(Pair("height",(int64_t)ptr->nodeheight)); + result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); + result.push_back(Pair("balance",(double)ptr->total/COIN)); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + result.push_back(Pair("interest",(double)ptr->interest/COIN)); + return(result); +} + +UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + result.push_back(Pair("prev",NSPV_ntz_json(&ptr->prevntz))); + result.push_back(Pair("next",NSPV_ntz_json(&ptr->nextntz))); + return(result); +} + +UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs) +{ + UniValue array(UniValue::VARR); int32_t i; + for (i=0; icommon.prevht)); + result.push_back(Pair("nextht",(int64_t)ptr->common.nextht)); + result.push_back(Pair("prevtxid",ptr->prevtxid.GetHex())); + result.push_back(Pair("prevtxidht",(int64_t)ptr->prevtxidht)); + result.push_back(Pair("prevtxlen",(int64_t)ptr->prevtxlen)); + result.push_back(Pair("nexttxid",ptr->nexttxid.GetHex())); + result.push_back(Pair("nexttxidht",(int64_t)ptr->nexttxidht)); + result.push_back(Pair("nexttxlen",(int64_t)ptr->prevtxlen)); + result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); + result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs))); + return(result); +} + +UniValue NSPV_login(char *wifstr) +{ + UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0; + len = bitcoin_base58decode(data,wifstr); + if ( strlen(wifstr) < 64 && (len == 38 && data[len-5] == 1) || (len == 37 && data[len-5] != 1) ) + valid = 1; + if ( valid == 0 || data[0] != 188 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid wif")); + result.push_back(Pair("len",(int64_t)len)); + result.push_back(Pair("prefix",(int64_t)data[0])); + return(result); + } + memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); + strncpy(NSPV_wifstr,wifstr,sizeof(NSPV_wifstr)-1); + NSPV_logintime = (uint32_t)time(NULL); + result.push_back(Pair("result","success")); + result.push_back(Pair("status","wif will expire in 60 seconds")); + NSPV_key = DecodeSecret(wifstr); + CPubKey pubkey = NSPV_key.GetPubKey(); + CKeyID vchAddress = pubkey.GetID(); + NSPV_address = EncodeDestination(vchAddress); + result.push_back(Pair("address",NSPV_address)); + result.push_back(Pair("pubkey",HexStr(pubkey))); + strcpy(NSPV_pubkeystr,HexStr(pubkey).c_str()); + result.push_back(Pair("wifprefix",(int64_t)data[0])); + result.push_back(Pair("compressed",(int64_t)(data[len-5] == 1))); + memset(data,0,sizeof(data)); + return(result); +} + +UniValue NSPV_getinfo_json() +{ + uint8_t msg[64]; int32_t i,iters,len = 0; struct NSPV_inforesp I; + NSPV_inforesp_purge(&NSPV_inforesult); + msg[len++] = NSPV_INFO; + for (iters=0; iters<3; iters++) + { + //fprintf(stderr,"issue getinfo\n"); + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + { + for (i=0; i>1); + } + slen = (int32_t)strlen(coinaddr); + msg[len++] = NSPV_UTXOS; + msg[len++] = slen; + memcpy(&msg[len],coinaddr,slen), len += slen; + msg[len] = 0; + if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) + { + for (i=0; i= NSPV_inforesult.height ) + return(NSPV_utxosresp_json(&NSPV_utxosresult)); + } + } + result.push_back(Pair("result","error")); + result.push_back(Pair("error","no utxos result")); + return(result); +} + +UniValue NSPV_notarizations(int32_t height) +{ + uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsresp N; + if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) + return(NSPV_ntzs_json(&NSPV_ntzsresult)); + msg[len++] = NSPV_NTZS; + len += iguana_rwnum(1,&msg[len],sizeof(height),&height); + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + { + for (i=0; i= height ) + return(NSPV_ntzs_json(&NSPV_ntzsresult)); + } + } + memset(&N,0,sizeof(N)); + return(NSPV_ntzs_json(&N)); +} + +UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) +{ + uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsproofresp H; + if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) + return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); + msg[len++] = NSPV_NTZSPROOF; + len += iguana_rwnum(1,&msg[len],sizeof(prevheight),&prevheight); + len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight); + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + { + for (i=0; i= nextheight ) + return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); + } + } + memset(&H,0,sizeof(H)); + return(NSPV_ntzsproof_json(&H)); +} + +UniValue NSPV_txproof(uint256 txid,int32_t height) +{ + uint8_t msg[64]; int32_t i,len = 0; struct NSPV_txproof P; + if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) + return(NSPV_txproof_json(&NSPV_txproofresult)); + msg[len++] = NSPV_TXPROOF; + len += iguana_rwnum(1,&msg[len],sizeof(height),&height); + len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); + //fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height); + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + { + for (i=0; i>1) != 0 ) + { + for (i=0; i response) // received a response +{ + int32_t len; uint32_t timestamp = (uint32_t)time(NULL); + if ( (len= response.size()) > 0 ) + { + switch ( response[0] ) + { + case NSPV_INFORESP: + NSPV_inforesp_purge(&NSPV_inforesult); + NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); + //fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status + break; + case NSPV_UTXOSRESP: + NSPV_utxosresp_purge(&NSPV_utxosresult); + NSPV_rwutxosresp(0,&response[1],&NSPV_utxosresult); + fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos list + break; + case NSPV_NTZSRESP: + NSPV_ntzsresp_purge(&NSPV_ntzsresult); + NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); + fprintf(stderr,"got ntzs response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] + break; + case NSPV_NTZSPROOFRESP: + NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); + NSPV_rwntzsproofresp(0,&response[1],&NSPV_ntzsproofresult); + fprintf(stderr,"got ntzproof response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsproofresult.common.prevht,NSPV_ntzsproofresult.common.nextht); // update utxos[i] + break; + case NSPV_TXPROOFRESP: + NSPV_txproof_purge(&NSPV_txproofresult); + NSPV_rwtxproof(0,&response[1],&NSPV_txproofresult); + fprintf(stderr,"got txproof response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] + break; + case NSPV_SPENTINFORESP: + + NSPV_spentinfo_purge(&NSPV_spentresult); + NSPV_rwspentinfo(0,&response[1],&NSPV_spentresult); + fprintf(stderr,"got spentinfo response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] + break; + default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); + break; + } + } +} + +#endif // KOMODO_NSPVSUPERLITE_H diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h new file mode 100644 index 000000000..1eb173dd5 --- /dev/null +++ b/src/komodo_nSPV_wallet.h @@ -0,0 +1,277 @@ + +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef KOMODO_NSPVWALLET_H +#define KOMODO_NSPVWALLET_H + +// nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_send + +int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) +{ + char *txstr; int32_t retval = 0; + NSPV_txproof(txid,height); + if ( NSPV_txproofresult.txid != txid || NSPV_txproofresult.height != height ) + return(-1); + txstr = (char *)malloc(NSPV_txproofresult.txlen*2 + 1); + init_hexbytes_noT(txstr,NSPV_txproofresult.tx,NSPV_txproofresult.txlen); + if ( !DecodeHexTx(tx,txstr) ) + retval = -1; + else + { + // need to validate txproof + // get the notarizations bracket of height + // get hdrsproof of the prev,next + // verify the hdrs link back from next to prev + // merkle prove txproof to the merkleroot in the corresponding hdr + } + free(txstr); + return(retval); +} + +int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) +{ + int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; + abovei = belowi = -1; + for (above=below=i=0; i value ) + { + gap = (atx_value - value); + if ( above == 0 || gap < above ) + { + above = gap; + abovei = i; + } + } + else + { + gap = (value - atx_value); + if ( below == 0 || gap < below ) + { + below = gap; + belowi = i; + } + } + //printf("value %.8f gap %.8f abovei.%d %.8f belowi.%d %.8f\n",dstr(value),dstr(gap),abovei,dstr(above),belowi,dstr(below)); + } + *aboveip = abovei; + *abovep = above; + *belowip = belowi; + *belowp = below; + //printf("above.%d below.%d\n",abovei,belowi); + if ( abovei >= 0 && belowi >= 0 ) + { + if ( above < (below >> 1) ) + return(abovei); + else return(belowi); + } + else if ( abovei >= 0 ) + return(abovei); + else return(belowi); +} + +int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t num) +{ + int32_t abovei,belowi,ind,vout,i,n = 0; int64_t threshold,above,below; int64_t remains,totalinputs = 0; CTransaction tx; struct NSPV_utxoresp utxos[NSPV_MAXVINS],*up; + memset(utxos,0,sizeof(utxos)); + if ( maxinputs > NSPV_MAXVINS ) + maxinputs = NSPV_MAXVINS; + if ( maxinputs > 0 ) + threshold = total/maxinputs; + else threshold = total; + for (i=0; i threshold ) + utxos[n++] = ptr[i]; + } + remains = total; + //fprintf(stderr,"n.%d for total %.8f\n",n,(double)total/COIN); + for (i=0; i0; i++) + { + below = above = 0; + abovei = belowi = -1; + if ( NSPV_vinselect(&abovei,&above,&belowi,&below,utxos,n,remains) < 0 ) + { + fprintf(stderr,"error finding unspent i.%d of %d, %.8f vs %.8f\n",i,n,(double)remains/COIN,(double)total/COIN); + free(utxos); + return(0); + } + if ( belowi < 0 || abovei >= 0 ) + ind = abovei; + else ind = belowi; + if ( ind < 0 ) + { + fprintf(stderr,"error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,n,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); + free(utxos); + return(0); + } + //fprintf(stderr,"i.%d ind.%d abovei.%d belowi.%d n.%d\n",i,ind,abovei,belowi,n); + up = &utxos[ind]; + mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); + used[i] = *up; + totalinputs += up->satoshis; + remains -= up->satoshis; + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); + fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); + if ( totalinputs >= total || (i+1) >= maxinputs ) + break; + } + fprintf(stderr,"totalinputs %.8f vs total %.8f\n",(double)totalinputs/COIN,(double)total/COIN); + if ( totalinputs >= total ) + return(totalinputs); + return(0); +} + +std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) +{ + auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + CTransaction vintx; std::string hex; uint256 hashBlock; int64_t change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n; + n = mtx.vout.size(); + for (i=0; i= totaloutputs+2*txfee ) + { + change = totalinputs - (totaloutputs+txfee); + mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(NSPV_pubkeystr) << OP_CHECKSIG)); + } + if ( opret.size() > 0 ) + mtx.vout.push_back(CTxOut(0,opret)); + fprintf(stderr,"sign %d inputs %.8f -> %d outputs %.8f change %.8f\n",(int32_t)mtx.vin.size(),(double)totalinputs/COIN,(int32_t)mtx.vout.size(),(double)totaloutputs/COIN,(double)change/COIN); + return(EncodeHexTx(mtx)); +} + +UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! +{ + UniValue result(UniValue::VOBJ); uint8_t rmd160[128]; int64_t txfee = 10000; + if ( strcmp(srcaddr,NSPV_address.c_str()) != 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid address")); + result.push_back(Pair("mismatched",srcaddr)); + return(result); + } + else if ( bitcoin_base58decode(rmd160,destaddr) != 25 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid destaddr")); + return(result); + } + if ( NSPV_inforesult.height == 0 ) + NSPV_getinfo_json(); + if ( NSPV_inforesult.height == 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt getinfo")); + return(result); + } + if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) + NSPV_addressutxos(srcaddr); + if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt get addressutxos")); + return(result); + } + if ( NSPV_utxosresult.total < satoshis+txfee ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough funds")); + result.push_back(Pair("balance",(double)NSPV_utxosresult.total/COIN)); + result.push_back(Pair("amount",(double)satoshis/COIN)); + return(result); + } + printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + std::vector data; CScript opret; std::string hex; + struct NSPV_utxoresp used[NSPV_MAXVINS]; + memset(used,0,sizeof(used)); + data.resize(20); + memcpy(&data[0],&rmd160[1],20); + if ( NSPV_addinputs(used,mtx,satoshis+txfee,64,NSPV_utxosresult.utxos,NSPV_utxosresult.numutxos) > 0 ) + { + fprintf(stderr,"vout\n"); + mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); + fprintf(stderr,"signtx\n"); + hex = NSPV_signtx(mtx,txfee,opret,used); + result.push_back(Pair("result","success")); + result.push_back(Pair("hex",hex)); + // prove all the vins + return(result); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt create tx")); + return(result); + } +} + +// polling loop (really this belongs in its own file, but it is so small, it ended up here) + +void komodo_nSPV(CNode *pto) // polling loop from SendMessages +{ + uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); + if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+60 ) + { + fprintf(stderr,"scrub wif from NSPV memory\n"); + memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); + memset(&NSPV_key,0,sizeof(NSPV_key)); + NSPV_logintime = 0; + } + if ( (pto->nServices & NODE_NSPV) == 0 ) + return; + if ( KOMODO_NSPV != 0 ) + { + if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) + { + len = 0; + msg[len++] = NSPV_INFO; + NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); + } + } +} + +#endif // KOMODO_NSPVWALLET_H diff --git a/src/main.cpp b/src/main.cpp index 27646ec0b..d6b3e0bb9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7046,7 +7046,10 @@ void static ProcessGetData(CNode* pfrom) } } -#include "komodo_nSPV.h" +#include "komodo_nSPV.h" // shared defines, structs, serdes, purge functions +#include "komodo_nSPV_fullnode.h" // nSPV fullnode handling of the getnSPV request messages +#include "komodo_nSPV_superlite.h" // nSPV superlite client, issuing requests and handling nSPV responses +#include "komodo_nSPV_wallet.h" // nSPV_send and support functions, really all the rest is to support this bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived) { From ad616b55c0f40541a7fe12b1f140af25f11e30a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 03:26:54 -1100 Subject: [PATCH 170/659] Syntax --- src/komodo_nSPV_wallet.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 1eb173dd5..7f460f716 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -114,7 +114,6 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 if ( NSPV_vinselect(&abovei,&above,&belowi,&below,utxos,n,remains) < 0 ) { fprintf(stderr,"error finding unspent i.%d of %d, %.8f vs %.8f\n",i,n,(double)remains/COIN,(double)total/COIN); - free(utxos); return(0); } if ( belowi < 0 || abovei >= 0 ) @@ -123,7 +122,6 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 if ( ind < 0 ) { fprintf(stderr,"error finding unspent i.%d of %d, %.8f vs %.8f, abovei.%d belowi.%d ind.%d\n",i,n,(double)remains/COIN,(double)total/COIN,abovei,belowi,ind); - free(utxos); return(0); } //fprintf(stderr,"i.%d ind.%d abovei.%d belowi.%d n.%d\n",i,ind,abovei,belowi,n); @@ -232,9 +230,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al memcpy(&data[0],&rmd160[1],20); if ( NSPV_addinputs(used,mtx,satoshis+txfee,64,NSPV_utxosresult.utxos,NSPV_utxosresult.numutxos) > 0 ) { - fprintf(stderr,"vout\n"); mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); - fprintf(stderr,"signtx\n"); hex = NSPV_signtx(mtx,txfee,opret,used); result.push_back(Pair("result","success")); result.push_back(Pair("hex",hex)); From 3f43c61f92be694647ea974709923b29bbf2c145 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 03:38:19 -1100 Subject: [PATCH 171/659] Dynamic keystone --- src/komodo-tx.cpp | 2 -- src/komodo_nSPV_superlite.h | 5 ----- src/komodo_nSPV_wallet.h | 14 +++++++++++++- src/script/sign.cpp | 7 +------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 807c4fae4..67ac68cd4 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -52,8 +52,6 @@ uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 return(0); } -CKey *NSPV_defaultkey() { return(0); } - static bool fCreateBlank; static std::map registers; static const int CONTINUE_EXECUTION=-1; diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index aeca64a9d..301dc9a2c 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -40,11 +40,6 @@ struct NSPV_ntzsproofresp NSPV_ntzsproofresult; struct NSPV_txproof NSPV_txproofresult; struct NSPV_utxo *NSPV_utxos; -CKey *NSPV_defaultkey() -{ - return(&NSPV_key); -} - CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t flag = 0; uint32_t timestamp = (uint32_t)time(NULL); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 7f460f716..cd54668b2 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -142,9 +142,21 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 return(0); } +bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) +{ + CTransaction txNewConst(mtx); SignatureData sigdata; const CKeyStore &keystore; + auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + keystore.AddKey(NSPV_key); + if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,consensusBranchId) != 0 ) + { + UpdateTransaction(mtx,vini,sigdata); + return(true); + } else fprintf(stderr,"signing error for SignTx vini.%d %.8f\n",vini,(double)utxovalue/COIN); + return(false); +} + std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) { - auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); CTransaction vintx; std::string hex; uint256 hashBlock; int64_t change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n; n = mtx.vout.size(); for (i=0; i valtype; extern uint8_t ASSETCHAINS_TXPOW; TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} -CKey *NSPV_defaultkey(); bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, const CKeyID& address, const CScript& scriptCode, uint32_t consensusBranchId, CKey *pprivKey, void *extraData) const { @@ -45,11 +44,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) - { - if ( (pprivKey= NSPV_defaultkey()) == 0 ) - return false; - else key = *pprivKey; - } + return false; uint256 hash; try { From bf39db459a64ea6bb33ab90251a201e86d3e6752 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 03:40:00 -1100 Subject: [PATCH 172/659] -& --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index cd54668b2..fa5f086e3 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -144,7 +144,7 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { - CTransaction txNewConst(mtx); SignatureData sigdata; const CKeyStore &keystore; + CTransaction txNewConst(mtx); SignatureData sigdata; const CKeyStore keystore; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); keystore.AddKey(NSPV_key); if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,consensusBranchId) != 0 ) From 20b81c6673c60304506daa76a208e2bfb0e83b50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 03:41:19 -1100 Subject: [PATCH 173/659] -const --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index fa5f086e3..4a33823ce 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -144,7 +144,7 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { - CTransaction txNewConst(mtx); SignatureData sigdata; const CKeyStore keystore; + CTransaction txNewConst(mtx); SignatureData sigdata; CKeyStore keystore; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); keystore.AddKey(NSPV_key); if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,consensusBranchId) != 0 ) From 62e8070ea7a891e41f559900eb96d19be2333956 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 03:46:44 -1100 Subject: [PATCH 174/659] CBasicKeyStore --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 4a33823ce..07d499a76 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -144,7 +144,7 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { - CTransaction txNewConst(mtx); SignatureData sigdata; CKeyStore keystore; + CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); keystore.AddKey(NSPV_key); if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,consensusBranchId) != 0 ) From 8f29da13404dc0700a9a577099c3ad71363b3060 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 03:52:24 -1100 Subject: [PATCH 175/659] 0x76b809bb --- src/komodo_nSPV_wallet.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 07d499a76..3acbe836e 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -19,6 +19,8 @@ // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_send +#define NSPV_BRANCHID 0x76b809bb + int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) { char *txstr; int32_t retval = 0; @@ -145,7 +147,7 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; - auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + auto consensusBranchId = NSPV_BRANCHID; keystore.AddKey(NSPV_key); if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,consensusBranchId) != 0 ) { From 6b6c7f19068734cc6cf6956766a5145879791585 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:06:27 -1100 Subject: [PATCH 176/659] Generate sapling tx --- src/komodo_nSPV_wallet.h | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 3acbe836e..01ad91cdb 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -134,11 +134,11 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 remains -= up->satoshis; utxos[ind] = utxos[--n]; memset(&utxos[n],0,sizeof(utxos[n])); - fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); + //fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break; } - fprintf(stderr,"totalinputs %.8f vs total %.8f\n",(double)totalinputs/COIN,(double)total/COIN); + //fprintf(stderr,"totalinputs %.8f vs total %.8f\n",(double)totalinputs/COIN,(double)total/COIN); if ( totalinputs >= total ) return(totalinputs); return(0); @@ -147,9 +147,8 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; - auto consensusBranchId = NSPV_BRANCHID; keystore.AddKey(NSPV_key); - if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,consensusBranchId) != 0 ) + if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) { UpdateTransaction(mtx,vini,sigdata); return(true); @@ -181,7 +180,10 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st return(""); } else if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) + { fprintf(stderr,"signing error for vini.%d\n",i); + return(""); + } } else fprintf(stderr,"couldnt find txid.%s\n",mtx.vin[i].prevout.hash.GetHex().c_str()); } if ( totalinputs >= totaloutputs+2*txfee ) @@ -236,19 +238,29 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al return(result); } printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - std::vector data; CScript opret; std::string hex; - struct NSPV_utxoresp used[NSPV_MAXVINS]; + std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; + mtx.fOverwintered = true; + mtx.nExpiryHeight = nHeight + expiryDelta; + mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; + mtx.nVersion = SAPLING_TX_VERSION; memset(used,0,sizeof(used)); data.resize(20); memcpy(&data[0],&rmd160[1],20); + if ( NSPV_addinputs(used,mtx,satoshis+txfee,64,NSPV_utxosresult.utxos,NSPV_utxosresult.numutxos) > 0 ) { mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); hex = NSPV_signtx(mtx,txfee,opret,used); - result.push_back(Pair("result","success")); - result.push_back(Pair("hex",hex)); - // prove all the vins + if ( hex.size() > 0 ) + { + result.push_back(Pair("result","success")); + result.push_back(Pair("hex",hex)); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","signing error")); + } return(result); } else From 78f26462ed5fa70f09bcbf366982c14c2365e44c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:07:18 -1100 Subject: [PATCH 177/659] Don't expire --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 01ad91cdb..296d000f1 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -240,7 +240,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; mtx.fOverwintered = true; - mtx.nExpiryHeight = nHeight + expiryDelta; + mtx.nExpiryHeight = 0; mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; memset(used,0,sizeof(used)); From 3837c804a96dcc413be14f0bb6b404f6bf7875e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:12:10 -1100 Subject: [PATCH 178/659] +print --- src/komodo_nSPV_wallet.h | 2 +- src/script/sign.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 296d000f1..e4f853aa2 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -152,7 +152,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C { UpdateTransaction(mtx,vini,sigdata); return(true); - } else fprintf(stderr,"signing error for SignTx vini.%d %.8f\n",vini,(double)utxovalue/COIN); + } // else fprintf(stderr,"signing error for SignTx vini.%d %.8f\n",vini,(double)utxovalue/COIN); return(false); } diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 685018828..f97e1a83d 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -44,7 +44,10 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) + { + fprintf(stderr,"couldnt find key\n"); return false; + } uint256 hash; try { From 44f805ce9e7a51f2148a6e2a3ec32d7daeb05514 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:19:03 -1100 Subject: [PATCH 179/659] +print --- src/keystore.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/keystore.cpp b/src/keystore.cpp index 34bab456c..0a79f7df7 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -71,6 +71,7 @@ bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) { LOCK(cs_KeyStore); mapKeys[pubkey.GetID()] = key; + fprintf(stderr,"addpubkey pub %s\n",pubkey.GetHex().c_str()); return true; } From a7685f00568e841ac643475e508fb21aba5565f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:22:26 -1100 Subject: [PATCH 180/659] +print --- src/keystore.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/keystore.cpp b/src/keystore.cpp index 0a79f7df7..8b794f2ce 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -71,7 +71,12 @@ bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) { LOCK(cs_KeyStore); mapKeys[pubkey.GetID()] = key; - fprintf(stderr,"addpubkey pub %s\n",pubkey.GetHex().c_str()); + { + int32_t i; + for (i=0; i<33; i++) + fprintf(stderr,"%02x",((uint8_t *)&pubkey)[i]); + fprintf(stderr," addpubkey pub\n"); + } return true; } From 9535f80ef9d64c4f56c84b7911ec0ccf6f631465 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:27:45 -1100 Subject: [PATCH 181/659] +print --- src/keystore.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/keystore.cpp b/src/keystore.cpp index 8b794f2ce..9da5a1e24 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -35,6 +35,7 @@ bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const } bool CKeyStore::AddKey(const CKey &key) { + fprintf(stderr,"addkey\n"); return AddKeyPubKey(key, key.GetPubKey()); } From 897981e00f1dd5830df9a9cc3e2feecb99235c5a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:33:02 -1100 Subject: [PATCH 182/659] +print --- src/komodo_nSPV_wallet.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index e4f853aa2..456d9e781 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -147,6 +147,7 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; + fprintf("call Addkey\n"); keystore.AddKey(NSPV_key); if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) { From b12183920c398125f952fd81328f2bcbc24b0c36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:33:54 -1100 Subject: [PATCH 183/659] +stderr --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 456d9e781..7381b1777 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -147,7 +147,7 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; - fprintf("call Addkey\n"); + fprintf(stderr,"call Addkey\n"); keystore.AddKey(NSPV_key); if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) { From 029a1865374b8cc5df7534da687ee67a5ec687f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:37:22 -1100 Subject: [PATCH 184/659] Use NSPV_SignTx --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 7381b1777..11d894a12 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -180,7 +180,7 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st fprintf(stderr,"vintx vout mismatch %d != %d\n",utxovout,used[i].vout); return(""); } - else if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) + else if ( NSPV_SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) { fprintf(stderr,"signing error for vini.%d\n",i); return(""); From 81d0e44732ce24a996c25437eb5023a8a4048ab2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:58:30 -1100 Subject: [PATCH 185/659] Guards for nSPV in decode/send raw transaction --- src/keystore.cpp | 7 ------- src/rpc/rawtransaction.cpp | 40 ++++++++++++++++++++------------------ src/script/sign.cpp | 3 --- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/keystore.cpp b/src/keystore.cpp index 9da5a1e24..34bab456c 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -35,7 +35,6 @@ bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const } bool CKeyStore::AddKey(const CKey &key) { - fprintf(stderr,"addkey\n"); return AddKeyPubKey(key, key.GetPubKey()); } @@ -72,12 +71,6 @@ bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) { LOCK(cs_KeyStore); mapKeys[pubkey.GetID()] = key; - { - int32_t i; - for (i=0; i<33; i++) - fprintf(stderr,"%02x",((uint8_t *)&pubkey)[i]); - fprintf(stderr," addpubkey pub\n"); - } return true; } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 7d490dff2..373eaae77 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -368,7 +368,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) entry.push_back(Pair("vin", vin)); UniValue vout(UniValue::VARR); BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *tipindex,*pindex = it->second; + CBlockIndex *tipindex;//,*pindex = it->second; uint64_t interest; for (unsigned int i = 0; i < tx.vout.size(); i++) { const CTxOut& txout = tx.vout[i]; @@ -1317,27 +1317,29 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp) bool fOverrideFees = false; if (params.size() > 1) fOverrideFees = params[1].get_bool(); - - CCoinsViewCache &view = *pcoinsTip; - const CCoins* existingCoins = view.AccessCoins(hashTx); - bool fHaveMempool = mempool.exists(hashTx); - bool fHaveChain = existingCoins && existingCoins->nHeight < 1000000000; - if (!fHaveMempool && !fHaveChain) { - // push to local node and sync with wallets - CValidationState state; - bool fMissingInputs; - if (!AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)) { - if (state.IsInvalid()) { - throw JSONRPCError(RPC_TRANSACTION_REJECTED, strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason())); - } else { - if (fMissingInputs) { - throw JSONRPCError(RPC_TRANSACTION_ERROR, "Missing inputs"); + if ( KOMODO_NSPV == 0 ) + { + CCoinsViewCache &view = *pcoinsTip; + const CCoins* existingCoins = view.AccessCoins(hashTx); + bool fHaveMempool = mempool.exists(hashTx); + bool fHaveChain = existingCoins && existingCoins->nHeight < 1000000000; + if (!fHaveMempool && !fHaveChain) { + // push to local node and sync with wallets + CValidationState state; + bool fMissingInputs; + if (!AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)) { + if (state.IsInvalid()) { + throw JSONRPCError(RPC_TRANSACTION_REJECTED, strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason())); + } else { + if (fMissingInputs) { + throw JSONRPCError(RPC_TRANSACTION_ERROR, "Missing inputs"); + } + throw JSONRPCError(RPC_TRANSACTION_ERROR, state.GetRejectReason()); } - throw JSONRPCError(RPC_TRANSACTION_ERROR, state.GetRejectReason()); } + } else if (fHaveChain) { + throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain"); } - } else if (fHaveChain) { - throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain"); } RelayTransaction(tx); diff --git a/src/script/sign.cpp b/src/script/sign.cpp index f97e1a83d..685018828 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -44,10 +44,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) - { - fprintf(stderr,"couldnt find key\n"); return false; - } uint256 hash; try { From e0489802a5ac8ad9223c8f73ff4c4d702c02d6aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 04:59:44 -1100 Subject: [PATCH 186/659] -pindex --- src/rpc/rawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 373eaae77..d60f0c52e 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -374,7 +374,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( ASSETCHAINS_SYMBOL[0] == 0 && pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->GetHeight()); From f3f63fea39cff2a841dca641cff8d2f956858f44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 05:15:34 -1100 Subject: [PATCH 187/659] +print --- src/komodo_nSPV_wallet.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 11d894a12..faba32eeb 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -147,8 +147,13 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; - fprintf(stderr,"call Addkey\n"); keystore.AddKey(NSPV_key); + { + int32_t i; + for (i=0; i Date: Fri, 5 Jul 2019 05:17:32 -1100 Subject: [PATCH 188/659] & --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index faba32eeb..570ca7217 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -151,7 +151,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C { int32_t i; for (i=0; i Date: Fri, 5 Jul 2019 05:20:35 -1100 Subject: [PATCH 189/659] +4 --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 570ca7217..65140fe54 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -150,7 +150,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C keystore.AddKey(NSPV_key); { int32_t i; - for (i=0; i Date: Fri, 5 Jul 2019 05:30:14 -1100 Subject: [PATCH 190/659] Finalize mtx before signing --- src/komodo_nSPV_wallet.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 65140fe54..bfdab6428 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -33,6 +33,7 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) retval = -1; else { + printf("got tx.(%s)\n",txstr); // need to validate txproof // get the notarizations bracket of height // get hdrsproof of the prev,next @@ -168,13 +169,21 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st n = mtx.vout.size(); for (i=0; i= totaloutputs+2*txfee ) + { + change = totalinputs - (totaloutputs+txfee); + mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(NSPV_pubkeystr) << OP_CHECKSIG)); + } + if ( opret.size() > 0 ) + mtx.vout.push_back(CTxOut(0,opret)); for (i=0; i= totaloutputs+2*txfee ) - { - change = totalinputs - (totaloutputs+txfee); - mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(NSPV_pubkeystr) << OP_CHECKSIG)); - } - if ( opret.size() > 0 ) - mtx.vout.push_back(CTxOut(0,opret)); fprintf(stderr,"sign %d inputs %.8f -> %d outputs %.8f change %.8f\n",(int32_t)mtx.vin.size(),(double)totalinputs/COIN,(int32_t)mtx.vout.size(),(double)totaloutputs/COIN,(double)change/COIN); return(EncodeHexTx(mtx)); } From 42cafb57375a35e208f0d77ce0d2d3f05d12d2af Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 05:34:59 -1100 Subject: [PATCH 191/659] Fixes --- src/komodo_nSPV_wallet.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index bfdab6428..80b02d619 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -18,6 +18,7 @@ #define KOMODO_NSPVWALLET_H // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_send +// interest calculations are currently just using what is returned, it should calculate it from scratch #define NSPV_BRANCHID 0x76b809bb @@ -33,7 +34,7 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) retval = -1; else { - printf("got tx.(%s)\n",txstr); + //printf("got tx.(%s)\n",txstr); // need to validate txproof // get the notarizations bracket of height // get hdrsproof of the prev,next @@ -165,17 +166,20 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) { - CTransaction vintx; std::string hex; uint256 hashBlock; int64_t change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n; + CTransaction vintx; std::string hex; uint256 hashBlock; int64_t interest=0,change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n; n = mtx.vout.size(); for (i=0; i= totaloutputs+2*txfee ) { - change = totalinputs - (totaloutputs+txfee); + totalinputs += used[i].satoshis; + interest += used[i].extradata; + } + //PrecomputedTransactionData txdata(mtx); + if ( (totalinputs+interest) >= totaloutputs+2*txfee ) + { + change = (totalinputs+interest) - (totaloutputs+txfee); mtx.vout.push_back(CTxOut(change,CScript() << ParseHex(NSPV_pubkeystr) << OP_CHECKSIG)); } if ( opret.size() > 0 ) @@ -201,7 +205,7 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st } } else fprintf(stderr,"couldnt find txid.%s\n",mtx.vin[i].prevout.hash.GetHex().c_str()); } - fprintf(stderr,"sign %d inputs %.8f -> %d outputs %.8f change %.8f\n",(int32_t)mtx.vin.size(),(double)totalinputs/COIN,(int32_t)mtx.vout.size(),(double)totaloutputs/COIN,(double)change/COIN); + fprintf(stderr,"sign %d inputs %.8f + interest %.8f -> %d outputs %.8f change %.8f\n",(int32_t)mtx.vin.size(),(double)totalinputs/COIN,(double)interest/COIN,(int32_t)mtx.vout.size(),(double)totaloutputs/COIN,(double)change/COIN); return(EncodeHexTx(mtx)); } From 1c4447716b49ef48c54b335f83e4ad01a87e4b88 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 05:37:47 -1100 Subject: [PATCH 192/659] utxovout = mtx.vin[i].prevout.n; --- src/komodo_nSPV_wallet.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 80b02d619..07e5580fb 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -188,6 +188,7 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st { if ( NSPV_gettransaction(mtx.vin[i].prevout.hash,used[i].height,vintx) == 0 ) { + utxovout = mtx.vin[i].prevout.n; if ( vintx.vout[utxovout].nValue != used[i].satoshis ) { fprintf(stderr,"vintx mismatch %.8f != %.8f\n",(double)vintx.vout[utxovout].nValue/COIN,(double)used[i].satoshis/COIN); From d2ce4d8277d29caeeeacd0c93563e5a0cdce0f8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 05:49:28 -1100 Subject: [PATCH 193/659] Add calls to get notarisation bracket and hdrsproof --- src/komodo_nSPV_wallet.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 07e5580fb..59a4acec0 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -36,9 +36,8 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) { //printf("got tx.(%s)\n",txstr); // need to validate txproof - // get the notarizations bracket of height - // get hdrsproof of the prev,next - // verify the hdrs link back from next to prev + NSPV_notarizations(height); // gets the prev and next notarizations + NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment // merkle prove txproof to the merkleroot in the corresponding hdr } free(txstr); @@ -150,6 +149,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C { CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; keystore.AddKey(NSPV_key); + if ( 0 ) { int32_t i; for (i=0; i Date: Fri, 5 Jul 2019 05:58:04 -1100 Subject: [PATCH 194/659] NSPV_AUTOLOGOUT --- src/komodo_nSPV_wallet.h | 10 ++++++++-- src/wallet/rpcdump.cpp | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 59a4acec0..cfe307eac 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -19,7 +19,7 @@ // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_send // interest calculations are currently just using what is returned, it should calculate it from scratch - +#define NSPV_AUTOLOGOUT 60 #define NSPV_BRANCHID 0x76b809bb int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) @@ -213,6 +213,12 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! { UniValue result(UniValue::VOBJ); uint8_t rmd160[128]; int64_t txfee = 10000; + if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","wif expired")); + return(result); + } if ( strcmp(srcaddr,NSPV_address.c_str()) != 0 ) { result.push_back(Pair("result","error")); @@ -289,7 +295,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al void komodo_nSPV(CNode *pto) // polling loop from SendMessages { uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); - if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+60 ) + if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT ) { fprintf(stderr,"scrub wif from NSPV memory\n"); memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index b13a2b6c9..97b458070 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -999,10 +999,10 @@ UniValue nspv_login(const UniValue& params, bool fHelp) UniValue nspv_listunspent(const UniValue& params, bool fHelp) { + if ( fHelp || params.size() > 1 ) + throw runtime_error("nspv_listunspent address\n"); if ( params.size() == 0 && NSPV_address.size() != 0 ) return(NSPV_addressutxos((char *)NSPV_address.c_str())); - if ( fHelp || params.size() != 1 ) - throw runtime_error("nspv_listunspent address\n"); return(NSPV_addressutxos((char *)params[0].get_str().c_str())); } From 07fe2a3a783718f3687bce0b789b0ef36d8e0340 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 06:11:32 -1100 Subject: [PATCH 195/659] Bypass all the other messages starting from inv --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index d6b3e0bb9..098396533 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7450,7 +7450,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, komodo_nSPVresp(pfrom,payload); return(true); } - + else if ( KOMODO_NSPV != 0 ) + return(true); else if (strCommand == "inv") { vector vInv; From 4bfb81956b1d93a6dc227ad550fcb65e9757ebbb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 06:22:40 -1100 Subject: [PATCH 196/659] +print --- src/net.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index c4c5fbc03..f3f763694 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1897,6 +1897,7 @@ void RelayTransaction(const CTransaction& tx) void RelayTransaction(const CTransaction& tx, const CDataStream& ss) { + fprintf(stderr,"RelayTransaction\n"); CInv inv(MSG_TX, tx.GetHash()); { LOCK(cs_mapRelay); @@ -1914,15 +1915,16 @@ void RelayTransaction(const CTransaction& tx, const CDataStream& ss) LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { + fprintf(stderr,"pnode relay tx.%d\n",(int32_t)pnode->fRelayTxes); if(!pnode->fRelayTxes) continue; + fprintf(stderr,"found pnode\n"); LOCK(pnode->cs_filter); if (pnode->pfilter) { if (pnode->pfilter->IsRelevantAndUpdate(tx)) pnode->PushInventory(inv); - } else - pnode->PushInventory(inv); + } else pnode->PushInventory(inv); } } From 21e87ec48fe629f6b44050c43927cac4aa6a102d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 06:26:01 -1100 Subject: [PATCH 197/659] +print --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 098396533..23f0acbce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7636,6 +7636,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (strCommand == "tx") { + fprintf(stderr,"got tx message\n"); if (IsInitialBlockDownload()) return true; @@ -7657,6 +7658,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) { + fprintf(stderr,"process new tx\n"); mempool.check(pcoinsTip); RelayTransaction(tx); vWorkQueue.push_back(inv.hash); From 7ebd4457680389f3e6af909da5f913352afaa3d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 06:33:15 -1100 Subject: [PATCH 198/659] -print --- src/komodo_nSPV_fullnode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index f493512a6..6982e619e 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -67,8 +67,8 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des txids[0] = nota.first; txidhts[0] = txidht; desttxids[0] = NSPV_extract_desttxid(&ntzheights[0],symbol,E_MARSHAL(ss << nota.second)); - if ( height != 2668 ) - fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); + //if ( height != 2668 ) + // fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); if ( ntzheights[0] == height-1 ) // offset the +1 from caller { txids[1] = txids[0]; From 7c6f471173acfe851e4ac7c60636b9d29687f8fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 06:57:09 -1100 Subject: [PATCH 199/659] Allow "inv" to be sent from superlite client --- src/main.cpp | 57 +++++++++++++++++++------------------- src/net.cpp | 3 -- src/rpc/rawtransaction.cpp | 1 - 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 23f0acbce..5407c9e91 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8243,35 +8243,35 @@ bool SendMessages(CNode* pto, bool fSendTrickle) state.fShouldBan = false; } komodo_nSPV(pto); - if ( KOMODO_NSPV != 0 ) - return(true); - BOOST_FOREACH(const CBlockReject& reject, state.rejects) - pto->PushMessage("reject", (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock); - state.rejects.clear(); - - // Start block sync - if (pindexBestHeader == NULL) - pindexBestHeader = chainActive.Tip(); - bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pindexBestHeader!=0) { - // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { - state.fSyncStarted = true; - nSyncStarted++; - CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; - LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->GetHeight(), pto->id, pto->nStartingHeight); - pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); + if ( KOMODO_NSPV == 0 ) + { + BOOST_FOREACH(const CBlockReject& reject, state.rejects) + pto->PushMessage("reject", (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock); + state.rejects.clear(); + + // Start block sync + if (pindexBestHeader == NULL) + pindexBestHeader = chainActive.Tip(); + bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pindexBestHeader!=0) { + // Only actively request headers from a single peer, unless we're close to today. + if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { + state.fSyncStarted = true; + nSyncStarted++; + CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; + LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->GetHeight(), pto->id, pto->nStartingHeight); + pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); + } + } + + // Resend wallet transactions that haven't gotten in a block yet + // Except during reindex, importing and IBD, when old wallet + // transactions become unconfirmed and spams other nodes. + if (!fReindex && !fImporting && !IsInitialBlockDownload()) + { + GetMainSignals().Broadcast(nTimeBestReceived); } } - - // Resend wallet transactions that haven't gotten in a block yet - // Except during reindex, importing and IBD, when old wallet - // transactions become unconfirmed and spams other nodes. - if (!fReindex && !fImporting && !IsInitialBlockDownload()) - { - GetMainSignals().Broadcast(nTimeBestReceived); - } - // // Message: inventory // @@ -8319,7 +8319,8 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } if (!vInv.empty()) pto->PushMessage("inv", vInv); - + if ( KOMODO_NSPV != 0 ) + return(true); // Detect whether we're stalling int64_t nNow = GetTimeMicros(); if (!pto->fDisconnect && state.nStallingSince && state.nStallingSince < nNow - 1000000 * BLOCK_STALLING_TIMEOUT) { diff --git a/src/net.cpp b/src/net.cpp index f3f763694..0586d7124 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1897,7 +1897,6 @@ void RelayTransaction(const CTransaction& tx) void RelayTransaction(const CTransaction& tx, const CDataStream& ss) { - fprintf(stderr,"RelayTransaction\n"); CInv inv(MSG_TX, tx.GetHash()); { LOCK(cs_mapRelay); @@ -1915,10 +1914,8 @@ void RelayTransaction(const CTransaction& tx, const CDataStream& ss) LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { - fprintf(stderr,"pnode relay tx.%d\n",(int32_t)pnode->fRelayTxes); if(!pnode->fRelayTxes) continue; - fprintf(stderr,"found pnode\n"); LOCK(pnode->cs_filter); if (pnode->pfilter) { diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index d60f0c52e..09247d311 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1342,7 +1342,6 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp) } } RelayTransaction(tx); - return hashTx.GetHex(); } From 329e181592023a077358599ba340ef94290497f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 06:59:01 -1100 Subject: [PATCH 200/659] Declare fFetch --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5407c9e91..9544c967a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8243,6 +8243,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) state.fShouldBan = false; } komodo_nSPV(pto); + bool fFetch = false; if ( KOMODO_NSPV == 0 ) { BOOST_FOREACH(const CBlockReject& reject, state.rejects) @@ -8252,7 +8253,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Start block sync if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); - bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. + fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pindexBestHeader!=0) { // Only actively request headers from a single peer, unless we're close to today. if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { From 4ae6f232a8ae6aacc92edf8211a847b18bb4b55f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 07:00:18 -1100 Subject: [PATCH 201/659] -print --- src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9544c967a..6b37fe32b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7636,7 +7636,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (strCommand == "tx") { - fprintf(stderr,"got tx message\n"); if (IsInitialBlockDownload()) return true; @@ -7658,7 +7657,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) { - fprintf(stderr,"process new tx\n"); mempool.check(pcoinsTip); RelayTransaction(tx); vWorkQueue.push_back(inv.hash); From 4fd98d4af3860eb4ed7d717f5ea6af63811ab326 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 07:02:39 -1100 Subject: [PATCH 202/659] +print --- src/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 6b37fe32b..b0e4092cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8317,7 +8317,10 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pto->vInventoryToSend = vInvWait; } if (!vInv.empty()) + { + fprintf(stderr,"send inv message\n"); pto->PushMessage("inv", vInv); + } if ( KOMODO_NSPV != 0 ) return(true); // Detect whether we're stalling From ad842844d5009d7ceca7af02814664273f48cc89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 07:07:01 -1100 Subject: [PATCH 203/659] Revert --- src/main.cpp | 61 ++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b0e4092cb..098396533 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8241,36 +8241,35 @@ bool SendMessages(CNode* pto, bool fSendTrickle) state.fShouldBan = false; } komodo_nSPV(pto); - bool fFetch = false; - if ( KOMODO_NSPV == 0 ) - { - BOOST_FOREACH(const CBlockReject& reject, state.rejects) - pto->PushMessage("reject", (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock); - state.rejects.clear(); - - // Start block sync - if (pindexBestHeader == NULL) - pindexBestHeader = chainActive.Tip(); - fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pindexBestHeader!=0) { - // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { - state.fSyncStarted = true; - nSyncStarted++; - CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; - LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->GetHeight(), pto->id, pto->nStartingHeight); - pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); - } - } - - // Resend wallet transactions that haven't gotten in a block yet - // Except during reindex, importing and IBD, when old wallet - // transactions become unconfirmed and spams other nodes. - if (!fReindex && !fImporting && !IsInitialBlockDownload()) - { - GetMainSignals().Broadcast(nTimeBestReceived); + if ( KOMODO_NSPV != 0 ) + return(true); + BOOST_FOREACH(const CBlockReject& reject, state.rejects) + pto->PushMessage("reject", (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock); + state.rejects.clear(); + + // Start block sync + if (pindexBestHeader == NULL) + pindexBestHeader = chainActive.Tip(); + bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pindexBestHeader!=0) { + // Only actively request headers from a single peer, unless we're close to today. + if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { + state.fSyncStarted = true; + nSyncStarted++; + CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; + LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->GetHeight(), pto->id, pto->nStartingHeight); + pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); } } + + // Resend wallet transactions that haven't gotten in a block yet + // Except during reindex, importing and IBD, when old wallet + // transactions become unconfirmed and spams other nodes. + if (!fReindex && !fImporting && !IsInitialBlockDownload()) + { + GetMainSignals().Broadcast(nTimeBestReceived); + } + // // Message: inventory // @@ -8317,12 +8316,8 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pto->vInventoryToSend = vInvWait; } if (!vInv.empty()) - { - fprintf(stderr,"send inv message\n"); pto->PushMessage("inv", vInv); - } - if ( KOMODO_NSPV != 0 ) - return(true); + // Detect whether we're stalling int64_t nNow = GetTimeMicros(); if (!pto->fDisconnect && state.nStallingSince && state.nStallingSince < nNow - 1000000 * BLOCK_STALLING_TIMEOUT) { From f542be0f7c461263ce9aba023a09ea76b74738b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 07:13:08 -1100 Subject: [PATCH 204/659] +fields --- src/komodo_nSPV_wallet.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index cfe307eac..3f4a4ec5b 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -245,6 +245,10 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { result.push_back(Pair("result","error")); + result.push_back(Pair("address",NSPV_utxosresult.coinaddr)); + result.push_back(Pair("srcaddr",srcaddr.coinaddr)); + result.push_back(Pair("nodeheight",(int64_t)NSPV_utxosresult.nodeheight)); + result.push_back(Pair("infoheight",(int64_t)NSPV_inforesult.height)); result.push_back(Pair("error","couldnt get addressutxos")); return(result); } From 169f9280f15393cdabcf05a6d0c0562211fd6204 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 5 Jul 2019 23:02:18 +0200 Subject: [PATCH 205/659] add ac_cbmaturity --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index d8e292431..9ffa147ea 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -46,7 +46,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; uint256 KOMODO_EARLYTXID; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,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,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,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,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1bf8dfbeb..59b3ce389 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1839,6 +1839,7 @@ void komodo_args(char *argv0) Split(GetArg("-ac_decay",""), ASSETCHAINS_DECAY, 0); Split(GetArg("-ac_notarypay",""), ASSETCHAINS_NOTARY_PAY, 0); + for ( int i = 0; i < ASSETCHAINS_MAX_ERAS; i++ ) { if ( ASSETCHAINS_DECAY[i] == 100000000 && ASSETCHAINS_ENDSUBSIDY == 0 ) @@ -1872,6 +1873,7 @@ void komodo_args(char *argv0) ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0); + ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",100); //fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET); if ( ASSETCHAINS_CBOPRET != 0 ) { @@ -2184,6 +2186,10 @@ void komodo_args(char *argv0) { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_EARLYTXIDCONTRACT),(void *)&ASSETCHAINS_EARLYTXIDCONTRACT); } + if ( ASSETCHAINS_CBMATURITY != 100 ) + { + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_CBMATURITY),(void *)&ASSETCHAINS_CBMATURITY); + } } addn = GetArg("-seednode",""); @@ -2234,8 +2240,15 @@ void komodo_args(char *argv0) } if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; - else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); - if (ASSETCHAINS_LASTERA == 0 || is_STAKED(ASSETCHAINS_SYMBOL) != 0) + else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1);\ + if (ASSETCHAINS_CBMATURITY < 1) + { + fprintf(stderr,"ac_cbmaturity must be >0\n"); + StartShutdown(); + } + if (ASSETCHAINS_CBMATURITY != 100) + COINBASE_MATURITY = ASSETCHAINS_CBMATURITY; + else if (ASSETCHAINS_LASTERA == 0 || is_STAKED(ASSETCHAINS_SYMBOL) != 0) COINBASE_MATURITY = 1; //fprintf(stderr,"ASSETCHAINS_RPCPORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_RPCPORT); } From 91330fe9a07fe201480a0d6adcaaf41a9819647f Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 5 Jul 2019 23:13:15 +0200 Subject: [PATCH 206/659] syntax, remove misplaced \ --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 59b3ce389..8993750c4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2240,7 +2240,7 @@ void komodo_args(char *argv0) } if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; - else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1);\ + else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); if (ASSETCHAINS_CBMATURITY < 1) { fprintf(stderr,"ac_cbmaturity must be >0\n"); From 8d0870e2c0e46492fcc4eea166d932b378b25612 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 5 Jul 2019 23:14:37 +0200 Subject: [PATCH 207/659] remove extra whitespace --- src/komodo_utils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8993750c4..1797c03fe 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1839,7 +1839,6 @@ void komodo_args(char *argv0) Split(GetArg("-ac_decay",""), ASSETCHAINS_DECAY, 0); Split(GetArg("-ac_notarypay",""), ASSETCHAINS_NOTARY_PAY, 0); - for ( int i = 0; i < ASSETCHAINS_MAX_ERAS; i++ ) { if ( ASSETCHAINS_DECAY[i] == 100000000 && ASSETCHAINS_ENDSUBSIDY == 0 ) From 29a2c5ba50916fdfb0e7fa290e369f43e319d431 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 5 Jul 2019 23:39:32 +0200 Subject: [PATCH 208/659] fix ac_cbmaturity=100 case --- src/komodo_utils.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1797c03fe..dbbc9ecaf 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1872,7 +1872,7 @@ void komodo_args(char *argv0) ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0); - ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",100); + ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",0); //fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET); if ( ASSETCHAINS_CBOPRET != 0 ) { @@ -2185,7 +2185,7 @@ void komodo_args(char *argv0) { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_EARLYTXIDCONTRACT),(void *)&ASSETCHAINS_EARLYTXIDCONTRACT); } - if ( ASSETCHAINS_CBMATURITY != 100 ) + if ( ASSETCHAINS_CBMATURITY != 0 ) { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_CBMATURITY),(void *)&ASSETCHAINS_CBMATURITY); } @@ -2240,15 +2240,16 @@ void komodo_args(char *argv0) if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); - if (ASSETCHAINS_CBMATURITY < 1) - { - fprintf(stderr,"ac_cbmaturity must be >0\n"); - StartShutdown(); - } - if (ASSETCHAINS_CBMATURITY != 100) + + if (ASSETCHAINS_CBMATURITY != 0) COINBASE_MATURITY = ASSETCHAINS_CBMATURITY; else if (ASSETCHAINS_LASTERA == 0 || is_STAKED(ASSETCHAINS_SYMBOL) != 0) COINBASE_MATURITY = 1; + if (COINBASE_MATURITY < 1) + { + fprintf(stderr,"ac_cbmaturity must be >0, shutting down\n"); + StartShutdown(); + } //fprintf(stderr,"ASSETCHAINS_RPCPORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_RPCPORT); } if ( ASSETCHAINS_RPCPORT == 0 ) From 754c912c2fe901491ffe2fee28cd254f07c938f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 19:56:07 -1100 Subject: [PATCH 209/659] Syntax --- src/komodo_nSPV_superlite.h | 3 +++ src/komodo_nSPV_wallet.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 301dc9a2c..982e751cf 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -21,6 +21,9 @@ // no caching, no optimizations, no reducing the number of ntzsproofs needed by detecting overlaps, etc. // advantage is that it is simpler to implement and understand to create a design for a more performant version +// interest calculations are currently just using what is returned, it should calculate it from scratch +// need to validate incoming data and update only if it is valid and more recent + #define NSPV_POLLITERS 15 #define NSPV_POLLMICROS 100000 #define NSPV_MAXVINS 64 diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 3f4a4ec5b..bada2cb33 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -18,7 +18,7 @@ #define KOMODO_NSPVWALLET_H // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_send -// interest calculations are currently just using what is returned, it should calculate it from scratch + #define NSPV_AUTOLOGOUT 60 #define NSPV_BRANCHID 0x76b809bb @@ -246,7 +246,7 @@ UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its al { result.push_back(Pair("result","error")); result.push_back(Pair("address",NSPV_utxosresult.coinaddr)); - result.push_back(Pair("srcaddr",srcaddr.coinaddr)); + result.push_back(Pair("srcaddr",srcaddr)); result.push_back(Pair("nodeheight",(int64_t)NSPV_utxosresult.nodeheight)); result.push_back(Pair("infoheight",(int64_t)NSPV_inforesult.height)); result.push_back(Pair("error","couldnt get addressutxos")); From ffd75096928798aaeab681d05352cb45209f181b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 22:13:06 -1100 Subject: [PATCH 210/659] nspv_send -> spend --- src/komodo_nSPV_wallet.h | 4 ++-- src/rpc/server.cpp | 2 +- src/rpc/server.h | 3 ++- src/wallet/rpcdump.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index bada2cb33..8fc0b3ce4 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -17,7 +17,7 @@ #ifndef KOMODO_NSPVWALLET_H #define KOMODO_NSPVWALLET_H -// nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_send +// nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_spend #define NSPV_AUTOLOGOUT 60 #define NSPV_BRANCHID 0x76b809bb @@ -210,7 +210,7 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st return(EncodeHexTx(mtx)); } -UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! +UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! { UniValue result(UniValue::VOBJ); uint8_t rmd160[128]; int64_t txfee = 10000; if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index c6a51d568..1d5cb83f1 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -424,7 +424,7 @@ static const CRPCCommand vRPCCommands[] = { "nSPV", "nspv_notarizations", &nspv_notarizations, true }, { "nSPV", "nspv_hdrsproof", &nspv_hdrsproof, true }, { "nSPV", "nspv_txproof", &nspv_txproof, true }, - { "nSPV", "nspv_send", &nspv_send, true }, + { "nSPV", "nspv_spend", &nspv_spend, true }, // rewards { "rewards", "rewardslist", &rewardslist, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 37cb3d26a..31da0e32f 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -462,7 +462,8 @@ extern UniValue nspv_spentinfo(const UniValue& params, bool fHelp); extern UniValue nspv_notarizations(const UniValue& params, bool fHelp); extern UniValue nspv_hdrsproof(const UniValue& params, bool fHelp); extern UniValue nspv_txproof(const UniValue& params, bool fHelp); -extern UniValue nspv_send(const UniValue& params, bool fHelp); +extern UniValue nspv_spend(const UniValue& params, bool fHelp); +extern UniValue nspv_broadcast(const UniValue& params, bool fHelp); extern UniValue getblocksubsidy(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 97b458070..c35b54965 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -975,7 +975,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) UniValue NSPV_getinfo_json(); UniValue NSPV_login(char *wifstr); UniValue NSPV_addressutxos(char *coinaddr); -UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis); +UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); UniValue NSPV_notarizations(int32_t height); UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight); @@ -1045,16 +1045,16 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp) return(NSPV_txproof(txid,height)); } -UniValue nspv_send(const UniValue& params, bool fHelp) +UniValue nspv_spend(const UniValue& params, bool fHelp) { uint64_t satoshis; if ( fHelp || params.size() != 2 ) - throw runtime_error("nspv_send destaddr amount\n"); + throw runtime_error("nspv_spend destaddr amount\n"); if ( NSPV_address.size() == 0 ) throw runtime_error("to nspv_send you need an active nspv_login\n"); satoshis = atof(params[1].get_str().c_str())*COIN + 0.0000000049; if ( satoshis < 1000 ) throw runtime_error("amount too small\n"); - return(NSPV_send((char *)NSPV_address.c_str(),(char *)params[0].get_str().c_str(),satoshis)); + return(NSPV_spend((char *)NSPV_address.c_str(),(char *)params[0].get_str().c_str(),satoshis)); } From cf4b5323fdab1f82c21a7cf52b962d94f416a332 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 23:26:01 -1100 Subject: [PATCH 211/659] Add nspv_broadcast, to all parts: rpc, superlite, full node A good example of how to add a new nSPV message, with corresponding rpc support --- src/komodo_nSPV.h | 26 +++++++++++++++++-- src/komodo_nSPV_fullnode.h | 47 ++++++++++++++++++++++++++++++++- src/komodo_nSPV_superlite.h | 52 ++++++++++++++++++++++++++++++++----- src/rpc/server.cpp | 1 + src/wallet/rpcdump.cpp | 7 +++++ 5 files changed, 123 insertions(+), 10 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 91c6ba7f4..fd90df5f4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -37,6 +37,8 @@ #define NSPV_TXPROOFRESP 0x09 #define NSPV_SPENTINFO 0x0a #define NSPV_SPENTINFORESP 0x0b +#define NSPV_BROADCAST 0x0c +#define NSPV_BROADCASTRESP 0x0d int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf) { @@ -254,7 +256,7 @@ void NSPV_txproof_purge(struct NSPV_txproof *ptr) } } -struct NSPV_utxo +/*struct NSPV_utxo { struct NSPV_txproof T; int64_t satoshis,extradata; @@ -272,7 +274,7 @@ int32_t NSPV_rwutxo(int32_t rwflag,uint8_t *serialized,struct NSPV_utxo *ptr) len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nextht),&ptr->nextht); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); return(len); -} +}*/ struct NSPV_ntzproofshared { @@ -361,4 +363,24 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) } } +struct NSPV_broadcastresp +{ + uint256 txid; + int32_t retcode; +}; + +int32_t NSPV_rwbroadcastresp(int32_t rwflag,uint8_t *serialized,struct NSPV_broadcastresp *ptr) +{ + int32_t len = 0; + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->retcode),&ptr->retcode); + return(len); +} + +void NSPV_broadcast_purge(struct NSPV_broadcastresp *ptr) +{ + if ( ptr != 0 ) + memset(ptr,0,sizeof(*ptr)); +} + #endif // KOMODO_NSPV_H diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 6982e619e..49259f13f 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -195,6 +195,26 @@ uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) return(rawtx); } +int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *tx,int32_t n) +{ + CTransaction tx; std::string rawtx; + ptr->retcode = 0; + rawtx.resize(n*2+1); + init_hexbytes_noT(rawtx.data(),tx,n); + fprintf(stderr,"rawtx.(%s)\n",rawtx.c_str()); + if ( DecodeHexTx(tx,rawtx) != 0 ) + { + ptr->txid = tx.GetHash(); + if ( myAddtomempool(tx) != 0 ) + { + fprintf(stderr,"relay transaction %s\n",ptr->txid.GetHex().c_str()); + RelayTransaction(tx); + ptr->retcode = 1; + } else ptr->retcode = 0; + } else ptr->retcode = -1; + return(sizeof(*ptr)); +} + int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) { int32_t flag = 0,len = 0; uint256 hashBlock; CBlock block; CBlockIndex *pindex; @@ -458,7 +478,32 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } } } - } + else if ( request[0] == NSPV_BROADCAST ) + { + if ( timestamp > pfrom->prevtimes[ind] ) + { + struct NSPV_broadcastresp B; uint16_t n,offset; uint256 txid; + if ( len > 1+sizeof(txid)+sizeof(n) ) + { + iguana_rwbignum(0,&request[1],sizeof(txid),(uint8_t *)&txid); + iguana_rwnum(0,&request[1+sizeof(txid)],sizeof(n),&n); + memset(&B,0,sizeof(B)); + offset = 1 + sizeof(txid) + sizeof(n); + if ( request.size() == offset+n && (slen= NSPV_sendrawtransaction(&B,&request[offset],n)) > 0 ) + { + response.resize(1 + slen); + response[0] = NSPV_BROADCASTRESP; + if ( NSPV_rwbroadcastresp(1,&response[1],&B) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_broadcast_purge(&S); + } + } + } + } + } } #endif // KOMODO_NSPVFULLNODE_H diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 982e751cf..482a0f330 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -41,7 +41,7 @@ struct NSPV_spentinfo NSPV_spentresult; struct NSPV_ntzsresp NSPV_ntzsresult; struct NSPV_ntzsproofresp NSPV_ntzsproofresult; struct NSPV_txproof NSPV_txproofresult; -struct NSPV_utxo *NSPV_utxos; +struct NSPV_broadcastresp NSPV_broadcastresult; CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { @@ -192,6 +192,15 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) return(result); } +UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + result.push_back(Pair("txid",ptr->txid.GetHex())); + result.push_back(Pair("retcode",(int64_t)ptr->retcode)); + return(result); +} + UniValue NSPV_login(char *wifstr) { UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0; @@ -364,6 +373,31 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) return(NSPV_spentinfo_json(&I)); } +UniValue NSPV_broadcast(char *hex) +{ + uint8_t msg[64],*tx; bits256 _txid; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresult B; + n = (int32_t)strlen(hex) >> 1; + tx = malloc(n); + decode_hex(tx,n,hex); + _txid = bits256_doublesha256(0,tx,n); + memcpy(&txid,_txid,sizeof(txid)); + msg[len++] = NSPV_BROADCAST; + len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); + len += iguana_rwnum(1,&msg[len],sizeof(n),&n); + memcpy(&msg[len],tx,n), len += n; + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + { + for (i=0; i response) // received a response { int32_t len; uint32_t timestamp = (uint32_t)time(NULL); @@ -384,25 +418,29 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_NTZSRESP: NSPV_ntzsresp_purge(&NSPV_ntzsresult); NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); - fprintf(stderr,"got ntzs response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] + fprintf(stderr,"got ntzs response %u size.%d\n",timestamp,(int32_t)response.size()); break; case NSPV_NTZSPROOFRESP: NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); NSPV_rwntzsproofresp(0,&response[1],&NSPV_ntzsproofresult); - fprintf(stderr,"got ntzproof response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsproofresult.common.prevht,NSPV_ntzsproofresult.common.nextht); // update utxos[i] + fprintf(stderr,"got ntzproof response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsproofresult.common.prevht,NSPV_ntzsproofresult.common.nextht); break; case NSPV_TXPROOFRESP: NSPV_txproof_purge(&NSPV_txproofresult); NSPV_rwtxproof(0,&response[1],&NSPV_txproofresult); - fprintf(stderr,"got txproof response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] + fprintf(stderr,"got txproof response %u size.%d\n",timestamp,(int32_t)response.size()); break; case NSPV_SPENTINFORESP: - NSPV_spentinfo_purge(&NSPV_spentresult); NSPV_rwspentinfo(0,&response[1],&NSPV_spentresult); - fprintf(stderr,"got spentinfo response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos[i] + fprintf(stderr,"got spentinfo response %u size.%d\n",timestamp,(int32_t)response.size()); break; - default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); + case NSPV_BROADCASTRESP: + NSPV_broadcast_purge(&NSPV_broadcastresult); + NSPV_rwbroadcast(0,&response[1],&NSPV_broadcastresult); + fprintf(stderr,"got broadcast response %u size.%d\n",timestamp,(int32_t)response.size()); + break; + default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); break; } } diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1d5cb83f1..36e4a8fda 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -425,6 +425,7 @@ static const CRPCCommand vRPCCommands[] = { "nSPV", "nspv_hdrsproof", &nspv_hdrsproof, true }, { "nSPV", "nspv_txproof", &nspv_txproof, true }, { "nSPV", "nspv_spend", &nspv_spend, true }, + { "nSPV", "nspv_broadcast", &nspv_broadcast, true }, // rewards { "rewards", "rewardslist", &rewardslist, true }, diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index c35b54965..225d32c80 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -975,6 +975,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) UniValue NSPV_getinfo_json(); UniValue NSPV_login(char *wifstr); UniValue NSPV_addressutxos(char *coinaddr); +UniValue NSPV_broadcast(char *hex); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); UniValue NSPV_notarizations(int32_t height); @@ -1058,3 +1059,9 @@ UniValue nspv_spend(const UniValue& params, bool fHelp) return(NSPV_spend((char *)NSPV_address.c_str(),(char *)params[0].get_str().c_str(),satoshis)); } +UniValue nspv_broadcast(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() != 1 ) + throw runtime_error("nspv_broadcast hex\n"); + return(NSPV_broadcast((char *)params[0].get_str().c_str())); +} From b9f914a323712a46669699501ec7d04f47870c27 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 23:29:44 -1100 Subject: [PATCH 212/659] Syntax --- src/komodo_nSPV_fullnode.h | 6 +++--- src/komodo_nSPV_superlite.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 49259f13f..af6c5d3f1 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -195,12 +195,12 @@ uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) return(rawtx); } -int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *tx,int32_t n) +int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int32_t n) { CTransaction tx; std::string rawtx; ptr->retcode = 0; rawtx.resize(n*2+1); - init_hexbytes_noT(rawtx.data(),tx,n); + init_hexbytes_noT((char *)rawtx.data(),data,n); fprintf(stderr,"rawtx.(%s)\n",rawtx.c_str()); if ( DecodeHexTx(tx,rawtx) != 0 ) { @@ -498,7 +498,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } - NSPV_broadcast_purge(&S); + NSPV_broadcast_purge(&B); } } } diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 482a0f330..3ed2e2f8f 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -375,7 +375,7 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) UniValue NSPV_broadcast(char *hex) { - uint8_t msg[64],*tx; bits256 _txid; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresult B; + uint8_t msg[64],*tx; bits256 _txid; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresp B; n = (int32_t)strlen(hex) >> 1; tx = malloc(n); decode_hex(tx,n,hex); From 4732e8a0ee91f1f6657fcef621bda2f04663563b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 23:31:20 -1100 Subject: [PATCH 213/659] Syntax --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 3ed2e2f8f..264add97e 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -377,10 +377,10 @@ UniValue NSPV_broadcast(char *hex) { uint8_t msg[64],*tx; bits256 _txid; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresp B; n = (int32_t)strlen(hex) >> 1; - tx = malloc(n); + tx = (uint8_t *)malloc(n); decode_hex(tx,n,hex); _txid = bits256_doublesha256(0,tx,n); - memcpy(&txid,_txid,sizeof(txid)); + memcpy(&txid,&_txid,sizeof(txid)); msg[len++] = NSPV_BROADCAST; len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); len += iguana_rwnum(1,&msg[len],sizeof(n),&n); @@ -437,7 +437,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r break; case NSPV_BROADCASTRESP: NSPV_broadcast_purge(&NSPV_broadcastresult); - NSPV_rwbroadcast(0,&response[1],&NSPV_broadcastresult); + NSPV_rwbroadcastresp(0,&response[1],&NSPV_broadcastresult); fprintf(stderr,"got broadcast response %u size.%d\n",timestamp,(int32_t)response.size()); break; default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); From f1e69bfde2f4a6e17fbfbe85b044ba424e48a06c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 23:42:01 -1100 Subject: [PATCH 214/659] Fix stack smashing --- src/komodo_nSPV_superlite.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 264add97e..d5dd7e269 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -375,25 +375,31 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) UniValue NSPV_broadcast(char *hex) { - uint8_t msg[64],*tx; bits256 _txid; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresp B; + uint8_t *msg,*data; bits256 _txid; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresp B; n = (int32_t)strlen(hex) >> 1; - tx = (uint8_t *)malloc(n); + data = (uint8_t *)malloc(n); decode_hex(tx,n,hex); - _txid = bits256_doublesha256(0,tx,n); + _txid = bits256_doublesha256(0,data,n); memcpy(&txid,&_txid,sizeof(txid)); + msg = malloc(1 + sizeof(txid) + sizeof(n) + n); msg[len++] = NSPV_BROADCAST; len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); len += iguana_rwnum(1,&msg[len],sizeof(n),&n); - memcpy(&msg[len],tx,n), len += n; + memcpy(&msg[len],data,n), len += n; + free(data); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i Date: Fri, 5 Jul 2019 23:45:23 -1100 Subject: [PATCH 215/659] Syntax --- src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_superlite.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index af6c5d3f1..320bdbd15 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -201,7 +201,7 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int ptr->retcode = 0; rawtx.resize(n*2+1); init_hexbytes_noT((char *)rawtx.data(),data,n); - fprintf(stderr,"rawtx.(%s)\n",rawtx.c_str()); + //fprintf(stderr,"rawtx.(%s)\n",rawtx.c_str()); if ( DecodeHexTx(tx,rawtx) != 0 ) { ptr->txid = tx.GetHash(); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d5dd7e269..bea83c38c 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -378,10 +378,10 @@ UniValue NSPV_broadcast(char *hex) uint8_t *msg,*data; bits256 _txid; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresp B; n = (int32_t)strlen(hex) >> 1; data = (uint8_t *)malloc(n); - decode_hex(tx,n,hex); + decode_hex(data,n,hex); _txid = bits256_doublesha256(0,data,n); memcpy(&txid,&_txid,sizeof(txid)); - msg = malloc(1 + sizeof(txid) + sizeof(n) + n); + msg = (uint8_t *)malloc(1 + sizeof(txid) + sizeof(n) + n); msg[len++] = NSPV_BROADCAST; len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); len += iguana_rwnum(1,&msg[len],sizeof(n),&n); From 21932cbbd52982752bbe46ecb83444f00908d6e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 23:51:31 -1100 Subject: [PATCH 216/659] +print --- src/komodo_nSPV_fullnode.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 320bdbd15..a29176255 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -204,13 +204,14 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int //fprintf(stderr,"rawtx.(%s)\n",rawtx.c_str()); if ( DecodeHexTx(tx,rawtx) != 0 ) { + LOCK(cs_main); ptr->txid = tx.GetHash(); + fprintf(stderr,"addmempool transaction %s\n",ptr->txid.GetHex().c_str()); if ( myAddtomempool(tx) != 0 ) - { - fprintf(stderr,"relay transaction %s\n",ptr->txid.GetHex().c_str()); - RelayTransaction(tx); ptr->retcode = 1; - } else ptr->retcode = 0; + else ptr->retcode = 0; + fprintf(stderr,"relay transaction %s\n",ptr->txid.GetHex().c_str()); + RelayTransaction(tx); } else ptr->retcode = -1; return(sizeof(*ptr)); } From a04b17f8df77f7cf8412d7f063f80ba847ffd9a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 23:58:16 -1100 Subject: [PATCH 217/659] Tweaks --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_fullnode.h | 10 +++++----- src/komodo_nSPV_superlite.h | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fd90df5f4..98ec7cd52 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -374,6 +374,7 @@ int32_t NSPV_rwbroadcastresp(int32_t rwflag,uint8_t *serialized,struct NSPV_broa int32_t len = 0; len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->retcode),&ptr->retcode); + fprintf(stderr,"broadcastresp[%d]\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index a29176255..bc3003dd4 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -197,12 +197,11 @@ uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int32_t n) { - CTransaction tx; std::string rawtx; + CTransaction tx; std::vector rawdata; ptr->retcode = 0; - rawtx.resize(n*2+1); - init_hexbytes_noT((char *)rawtx.data(),data,n); - //fprintf(stderr,"rawtx.(%s)\n",rawtx.c_str()); - if ( DecodeHexTx(tx,rawtx) != 0 ) + rawdata.resize(n); + memcpy(&rawdata[0],data,n); + if ( DecodeHexTx(tx,rawdata.GetHex()) != 0 ) { LOCK(cs_main); ptr->txid = tx.GetHash(); @@ -494,6 +493,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_BROADCASTRESP; + fprintf(stderr,"slen.%d\n"); if ( NSPV_rwbroadcastresp(1,&response[1],&B) == slen ) { pfrom->PushMessage("nSPV",response); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index bea83c38c..c7aec72ad 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -401,6 +401,7 @@ UniValue NSPV_broadcast(char *hex) } free(msg); memset(&B,0,sizeof(B)); + B.retcode = -2; return(NSPV_broadcast_json(&B)); } From 7c0ad48d79f60d03e2f83ff54c284a34aa4b1ff4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 00:00:58 -1100 Subject: [PATCH 218/659] ToString --- src/komodo_nSPV_fullnode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index bc3003dd4..3705e06b3 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -201,7 +201,7 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int ptr->retcode = 0; rawdata.resize(n); memcpy(&rawdata[0],data,n); - if ( DecodeHexTx(tx,rawdata.GetHex()) != 0 ) + if ( DecodeHexTx(tx,rawdata.ToString()) != 0 ) { LOCK(cs_main); ptr->txid = tx.GetHash(); @@ -493,7 +493,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_BROADCASTRESP; - fprintf(stderr,"slen.%d\n"); + fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwbroadcastresp(1,&response[1],&B) == slen ) { pfrom->PushMessage("nSPV",response); From 9aef2cddf29d16e110f15def92a29fcbccd6c2d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 00:04:44 -1100 Subject: [PATCH 219/659] Hexstr --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 3705e06b3..3eb2538c8 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -201,7 +201,7 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int ptr->retcode = 0; rawdata.resize(n); memcpy(&rawdata[0],data,n); - if ( DecodeHexTx(tx,rawdata.ToString()) != 0 ) + if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) { LOCK(cs_main); ptr->txid = tx.GetHash(); From 1d7abe07044a3617feb50224c919a03ba12d3ebc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 00:10:52 -1100 Subject: [PATCH 220/659] +print --- src/komodo_nSPV_superlite.h | 2 +- src/komodo_nSPV_wallet.h | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index c7aec72ad..6bac1e1f2 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -445,7 +445,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_BROADCASTRESP: NSPV_broadcast_purge(&NSPV_broadcastresult); NSPV_rwbroadcastresp(0,&response[1],&NSPV_broadcastresult); - fprintf(stderr,"got broadcast response %u size.%d\n",timestamp,(int32_t)response.size()); + fprintf(stderr,"got broadcast response %u size.%d %s retcode.%d\n",timestamp,(int32_t)response.size(),NSPV_broadcastresult.txid.GetHex().c_str(),NSPV_broadcastresult.retcode); break; default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); break; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 8fc0b3ce4..b4d914729 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -261,7 +261,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); - std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; + std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction; mtx.fOverwintered = true; mtx.nExpiryHeight = 0; mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; @@ -276,8 +276,17 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a hex = NSPV_signtx(mtx,txfee,opret,used); if ( hex.size() > 0 ) { - result.push_back(Pair("result","success")); - result.push_back(Pair("hex",hex)); + if ( DecodeHexTx(tx,hex) != 0 ) + { + TxToJSON(tx,uint256(),result); + result.push_back(Pair("result","success")); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt decode")); + result.push_back(Pair("hex",hex)); + } } else { From 818019a6dc819d1ba03635c2f7e47563be8799ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 00:13:00 -1100 Subject: [PATCH 221/659] Syntax --- src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_wallet.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 3eb2538c8..62d1411bd 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -209,7 +209,7 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int if ( myAddtomempool(tx) != 0 ) ptr->retcode = 1; else ptr->retcode = 0; - fprintf(stderr,"relay transaction %s\n",ptr->txid.GetHex().c_str()); + fprintf(stderr,"relay transaction %s retcode.%d\n",ptr->txid.GetHex().c_str(),ptr->retcode); RelayTransaction(tx); } else ptr->retcode = -1; return(sizeof(*ptr)); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index b4d914729..5aa1fd038 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -18,6 +18,7 @@ #define KOMODO_NSPVWALLET_H // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_spend +extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); #define NSPV_AUTOLOGOUT 60 #define NSPV_BRANCHID 0x76b809bb @@ -261,7 +262,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); - std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction; + std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction tx; mtx.fOverwintered = true; mtx.nExpiryHeight = 0; mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; From 744718b1c99b4f2bdb1d678cdc5aa111a15fba88 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 00:19:12 -1100 Subject: [PATCH 222/659] +print --- src/komodo_nSPV.h | 1 - src/komodo_nSPV_fullnode.h | 5 ++--- src/komodo_nSPV_superlite.h | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 98ec7cd52..fd90df5f4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -374,7 +374,6 @@ int32_t NSPV_rwbroadcastresp(int32_t rwflag,uint8_t *serialized,struct NSPV_broa int32_t len = 0; len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->retcode),&ptr->retcode); - fprintf(stderr,"broadcastresp[%d]\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 62d1411bd..5a05d01ae 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -205,11 +205,11 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int { LOCK(cs_main); ptr->txid = tx.GetHash(); - fprintf(stderr,"addmempool transaction %s\n",ptr->txid.GetHex().c_str()); + //fprintf(stderr,"addmempool transaction %s\n",ptr->txid.GetHex().c_str()); if ( myAddtomempool(tx) != 0 ) ptr->retcode = 1; else ptr->retcode = 0; - fprintf(stderr,"relay transaction %s retcode.%d\n",ptr->txid.GetHex().c_str(),ptr->retcode); + //fprintf(stderr,"relay transaction %s retcode.%d\n",ptr->txid.GetHex().c_str(),ptr->retcode); RelayTransaction(tx); } else ptr->retcode = -1; return(sizeof(*ptr)); @@ -493,7 +493,6 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_BROADCASTRESP; - fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwbroadcastresp(1,&response[1],&B) == slen ) { pfrom->PushMessage("nSPV",response); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 6bac1e1f2..da34b4c34 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -387,6 +387,7 @@ UniValue NSPV_broadcast(char *hex) len += iguana_rwnum(1,&msg[len],sizeof(n),&n); memcpy(&msg[len],data,n), len += n; free(data); + fprintf(stderr,"send txid.%s\n",txid.GetHex().c_str()); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i Date: Sat, 6 Jul 2019 00:24:26 -1100 Subject: [PATCH 223/659] Fix --- src/komodo_nSPV_superlite.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index da34b4c34..35da59efd 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -192,12 +192,21 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) return(result); } -UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr) +UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid) { UniValue result(UniValue::VOBJ); result.push_back(Pair("result","success")); - result.push_back(Pair("txid",ptr->txid.GetHex())); + result.push_back(Pair("expected",txid.GetHex())); + result.push_back(Pair("broadcast",ptr->txid.GetHex())); result.push_back(Pair("retcode",(int64_t)ptr->retcode)); + switch ( ptr->retcode ) + { + case 1: result.push_back(Pair("type","broadcast and mempool")); break; + case 0: result.push_back(Pair("type","broadcast")); break; + case -1: result.push_back(Pair("type","decode error")); break; + case -2: result.push_back(Pair("type","timeout")); break; + default: result.push_back(Pair("type","unknown")); break; + } return(result); } @@ -380,7 +389,8 @@ UniValue NSPV_broadcast(char *hex) data = (uint8_t *)malloc(n); decode_hex(data,n,hex); _txid = bits256_doublesha256(0,data,n); - memcpy(&txid,&_txid,sizeof(txid)); + for (i=0; i<32; i++) + ((uint8_t *)&txid[i] = _txid.bytes[31 - i]; msg = (uint8_t *)malloc(1 + sizeof(txid) + sizeof(n) + n); msg[len++] = NSPV_BROADCAST; len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); @@ -396,14 +406,14 @@ UniValue NSPV_broadcast(char *hex) if ( NSPV_broadcastresult.txid == txid ) { free(msg); - return(NSPV_broadcast_json(&NSPV_broadcastresult)); + return(NSPV_broadcast_json(&NSPV_broadcastresult,txid)); } } } free(msg); memset(&B,0,sizeof(B)); B.retcode = -2; - return(NSPV_broadcast_json(&B)); + return(NSPV_broadcast_json(&B,txid)); } void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response From 3bf999989d35bc4e1249298c7d6e268a6fbacc6e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 00:26:28 -1100 Subject: [PATCH 224/659] ) --- src/komodo_nSPV_superlite.h | 4 ++-- src/rpc/rawtransaction.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 35da59efd..a2f80b79e 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -390,14 +390,14 @@ UniValue NSPV_broadcast(char *hex) decode_hex(data,n,hex); _txid = bits256_doublesha256(0,data,n); for (i=0; i<32; i++) - ((uint8_t *)&txid[i] = _txid.bytes[31 - i]; + ((uint8_t *)&txid)[i] = _txid.bytes[31 - i]; msg = (uint8_t *)malloc(1 + sizeof(txid) + sizeof(n) + n); msg[len++] = NSPV_BROADCAST; len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); len += iguana_rwnum(1,&msg[len],sizeof(n),&n); memcpy(&msg[len],data,n), len += n; free(data); - fprintf(stderr,"send txid.%s\n",txid.GetHex().c_str()); + //fprintf(stderr,"send txid.%s\n",txid.GetHex().c_str()); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i 2) @@ -1340,8 +1342,12 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp) } else if (fHaveChain) { throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain"); } + RelayTransaction(tx); + } + else + { + NSPV_broadcast((char *)params[0].get_str().c_str()); } - RelayTransaction(tx); return hashTx.GetHex(); } From b35d0253887e519f58846bd1352ecddef224b871 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 00:30:28 -1100 Subject: [PATCH 225/659] Add hex --- src/komodo_nSPV_wallet.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 5aa1fd038..c96aa99db 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -281,6 +281,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a { TxToJSON(tx,uint256(),result); result.push_back(Pair("result","success")); + result.push_back(Pair("hex",hex)); } else { From 64915ad6d2ce2702ff691fc1548e2524fb03dee2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 03:03:01 -1100 Subject: [PATCH 226/659] Fix spamming --- src/bitcoind.cpp | 3 ++- src/komodo_nSPV.h | 29 ++++++++----------------- src/komodo_nSPV_superlite.h | 6 ++---- src/komodo_nSPV_wallet.h | 43 +++++++++++++++++++++++++++++++++---- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 68e0da8b3..ff329a0d6 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -77,7 +77,8 @@ void WaitForShutdown(boost::thread_group* threadGroup) //fprintf(stderr,"call passport iteration\n"); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - komodo_passport_iteration(); + if ( KOMODO_NSPV == 0 ) + komodo_passport_iteration(); for (i=0; i<10; i++) { fShutdown = ShutdownRequested(); diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fd90df5f4..56ec85488 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -256,26 +256,6 @@ void NSPV_txproof_purge(struct NSPV_txproof *ptr) } } -/*struct NSPV_utxo -{ - struct NSPV_txproof T; - int64_t satoshis,extradata; - int32_t vout,prevht,nextht,pad32; -}; - -int32_t NSPV_rwutxo(int32_t rwflag,uint8_t *serialized,struct NSPV_utxo *ptr) -{ - int32_t len = 0; - len += NSPV_rwtxproof(rwflag,&serialized[len],&ptr->T); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->satoshis),&ptr->satoshis); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->extradata),&ptr->extradata); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevht),&ptr->prevht); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nextht),&ptr->nextht); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); - return(len); -}*/ - struct NSPV_ntzproofshared { struct NSPV_equihdr *hdrs; @@ -383,4 +363,13 @@ void NSPV_broadcast_purge(struct NSPV_broadcastresp *ptr) memset(ptr,0,sizeof(*ptr)); } +uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) +{ + bits256 _hash; uint256 hash; + _hash = bits256_doublesha256(0,data,datalen); + for (i=0; i<32; i++) + ((uint8_t *)&hash)[i] = _hash.bytes[31 - i]; + return(hash); +} + #endif // KOMODO_NSPV_H diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index a2f80b79e..ade2c8115 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -384,13 +384,11 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) UniValue NSPV_broadcast(char *hex) { - uint8_t *msg,*data; bits256 _txid; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresp B; + uint8_t *msg,*data; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresp B; n = (int32_t)strlen(hex) >> 1; data = (uint8_t *)malloc(n); decode_hex(data,n,hex); - _txid = bits256_doublesha256(0,data,n); - for (i=0; i<32; i++) - ((uint8_t *)&txid)[i] = _txid.bytes[31 - i]; + txid = NSPV_doublesha256(data,n); msg = (uint8_t *)malloc(1 + sizeof(txid) + sizeof(n) + n); msg[len++] = NSPV_BROADCAST; len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index c96aa99db..d53d0c8a1 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -23,6 +23,37 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& #define NSPV_AUTOLOGOUT 60 #define NSPV_BRANCHID 0x76b809bb + +/*struct NSPV_ntzproofshared +{ + struct NSPV_equihdr *hdrs; + int32_t prevht,nextht,pad32; + uint16_t numhdrs,pad16; +}; + +struct NSPV_ntzsproofresp +{ + struct NSPV_ntzproofshared common; + uint256 prevtxid,nexttxid; + int32_t pad32,prevtxidht,nexttxidht; + uint16_t prevtxlen,nexttxlen; + uint8_t *prevntz,*nextntz; +};*/ + +int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresult *ptr) +{ + int32_t i; + // verify nextntz is valid notarization + // validate blockhash of lasthdr with nextntz value, and height + for (i=numhdrs-1; i>0; i--) + { + // make sure the hash of i-1 matches the prevBlockhash of i + } + // verify prevntz is valid notarization + // verify blockhash of first hdr with prevntz value and height + return(0); +} + int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) { char *txstr; int32_t retval = 0; @@ -35,11 +66,15 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) retval = -1; else { - //printf("got tx.(%s)\n",txstr); - // need to validate txproof NSPV_notarizations(height); // gets the prev and next notarizations - NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment - // merkle prove txproof to the merkleroot in the corresponding hdr + if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) + { + NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment + if ( NSPV_validatehdrs(&NSPV_ntzsproofresult) == 0 ) + { + // merkle prove txproof to the merkleroot in the corresponding hdr + } + } else retval = -1; } free(txstr); return(retval); From 6db0b511b9c1c738279583c34bdf4d7b9f14fdd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 03:05:04 -1100 Subject: [PATCH 227/659] Syntax --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_wallet.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 56ec85488..1df9aedf4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -365,7 +365,7 @@ void NSPV_broadcast_purge(struct NSPV_broadcastresp *ptr) uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) { - bits256 _hash; uint256 hash; + bits256 _hash; uint256 hash; int32_t i; _hash = bits256_doublesha256(0,data,datalen); for (i=0; i<32; i++) ((uint8_t *)&hash)[i] = _hash.bytes[31 - i]; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index d53d0c8a1..d97821fb1 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -40,12 +40,12 @@ struct NSPV_ntzsproofresp uint8_t *prevntz,*nextntz; };*/ -int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresult *ptr) +int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) { int32_t i; // verify nextntz is valid notarization // validate blockhash of lasthdr with nextntz value, and height - for (i=numhdrs-1; i>0; i--) + for (i=ptr->common.numhdrs-1; i>0; i--) { // make sure the hash of i-1 matches the prevBlockhash of i } From 252f51adc58cec35d892e8df2112220630127b3f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 03:34:59 -1100 Subject: [PATCH 228/659] Very partial CC signing support --- src/cc/CCinclude.h | 1 + src/cc/CCtx.cpp | 20 ++++++++++++++++++-- src/cc/CCutils.cpp | 6 ++++++ src/komodo_nSPV_superlite.h | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 1d8cf669e..85ff380ca 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -289,6 +289,7 @@ void SetCCtxids(std::vector > &addressIndex int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs); int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag); +bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); // curve25519 and sha256 bits256 curve25519_shared(bits256 privkey,bits256 otherpub); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 7435defbf..b51342be7 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -150,8 +150,16 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran utxovout = mtx.vin[i].prevout.n; if ( vintx.vout[utxovout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) - fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask); + if ( KOMODO_NSPV == 0 ) + { + if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) + fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask); + } + else + { + if ( NSPV_SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) + fprintf(stderr,"NSPV signing error for vini.%d of %llx\n",i,(long long)vinimask); + } } else { @@ -510,6 +518,10 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + if ( KOMODO_NSPV != 0 ) + { + //return(NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t num)); + } #ifdef ENABLE_WALLET assert(pwalletMain != NULL); const CKeyStore& keystore = *pwalletMain; @@ -605,6 +617,10 @@ int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinput { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; std::vector > unspentOutputs; + if ( KOMODO_NSPV != 0 ) + { + //return(NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t num)); + } utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos)); if ( maxinputs > CC_MAXVINS ) maxinputs = CC_MAXVINS; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 5de5ed0db..699b84727 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -437,9 +437,15 @@ std::vector Mypubkey() return(pubkey); } +extern CKey NSPV_key; bool Myprivkey(uint8_t myprivkey[]) { char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33]; + if ( KOMODO_NSPV != 0 ) + { + memcpy(myprivkey,NSPV_key.vch,32); + return true; + } if ( Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG) != 0 ) { n = (int32_t)strlen(coinaddr); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index ade2c8115..9a3f459b0 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -236,6 +236,8 @@ UniValue NSPV_login(char *wifstr) result.push_back(Pair("address",NSPV_address)); result.push_back(Pair("pubkey",HexStr(pubkey))); strcpy(NSPV_pubkeystr,HexStr(pubkey).c_str()); + if ( KOMODO_NSPV != 0 ) + decode_hex(NOTARY_PUBKEY33,33,NSPV_pubkeystr); result.push_back(Pair("wifprefix",(int64_t)data[0])); result.push_back(Pair("compressed",(int64_t)(data[len-5] == 1))); memset(data,0,sizeof(data)); From 559c2cf8ffa1b14f57e641893f862ad160443760 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 03:38:51 -1100 Subject: [PATCH 229/659] myprivkey --- src/cc/CCutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 699b84727..3c67b4068 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -443,7 +443,7 @@ bool Myprivkey(uint8_t myprivkey[]) char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33]; if ( KOMODO_NSPV != 0 ) { - memcpy(myprivkey,NSPV_key.vch,32); + NSPV_key.SetKey32(myprivkey); return true; } if ( Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG) != 0 ) From 1d4b40c9123f8bb42dc1cf9095d525f79739c244 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 03:43:28 -1100 Subject: [PATCH 230/659] Skip params if nSPV --- src/init.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 7e131b759..f2335ce38 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1302,9 +1302,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) libsnark::inhibit_profiling_info = true; libsnark::inhibit_profiling_counters = true; - // Initialize Zcash circuit parameters - ZC_LoadParams(chainparams); - + if ( KOMODO_NSPV == 0 ) + { + // Initialize Zcash circuit parameters + ZC_LoadParams(chainparams); + } /* Start the RPC server already. It will be started in "warmup" mode * and not really process calls already (but it will signify connections * that the server is there and will be ready later). Warmup mode will From 793f0e3227a65c97cc2f9e0022dd10b4fd784641 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Sat, 6 Jul 2019 19:16:53 +0200 Subject: [PATCH 231/659] jokers payments fix --- src/cc/payments.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index b6e85480c..be4d63271 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -314,6 +314,8 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & fIsMerge = true; else if ( DecodePaymentsReleaseOpRet(ccopret,createtxid,amountReleased) != 'R' ) return(eval->Invalid("could not decode ccopret")); + if ( tx.vout.back().scriptPubKey.IsOpReturn() ) + fHasOpret = true; mpz_set_si(mpzCheckamount,amountReleased); } else return(eval->Invalid("could not decode ccopret")); From 685056e890d90eba50883d6bd69e34f22dcc450a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 07:19:44 -1100 Subject: [PATCH 232/659] Getnewaddress for nSPV mode --- src/wallet/rpcwallet.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 955118346..e463af829 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -176,6 +176,19 @@ UniValue getnewaddress(const UniValue& params, bool fHelp) + HelpExampleRpc("getnewaddress", "") ); + if ( KOMODO_NSPV != 0 ) + { + uint8_t priv32[32]; +#ifndef __WIN32 + OS_randombytes(priv32,sizeof(priv32)); +#else + randombytes_buf(priv32,sizeof(priv32)); +#endif + key.Set(&priv[0],&priv[32], true); + CPubKey pubkey = key.GetPubKey(); + CKeyID vchAddress = pubkey.GetID(); + return(EncodeDestination(vchAddress)); + } LOCK2(cs_main, pwalletMain->cs_wallet); // Parse the account first so we don't generate a key if there's an error From 6ebbdf83033780ef608f0dd109ae3afc5df9d70d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 07:24:18 -1100 Subject: [PATCH 233/659] Set nLockTime --- src/komodo_nSPV_wallet.h | 1 + src/wallet/rpcwallet.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index d97821fb1..bfcb5fecb 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -302,6 +302,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a mtx.nExpiryHeight = 0; mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; + mtx.nLockTime = (uint32_t)time(NULL) - 777; memset(used,0,sizeof(used)); data.resize(20); memcpy(&data[0],&rmd160[1],20); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e463af829..3ac705dff 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -158,6 +158,8 @@ char *komodo_chainname() return(ASSETCHAINS_SYMBOL[0] == 0 ? (char *)"KMD" : ASSETCHAINS_SYMBOL); } +void OS_randombytes(unsigned char *x,long xlen); + UniValue getnewaddress(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) @@ -184,7 +186,7 @@ UniValue getnewaddress(const UniValue& params, bool fHelp) #else randombytes_buf(priv32,sizeof(priv32)); #endif - key.Set(&priv[0],&priv[32], true); + key.Set(&priv32[0],&priv[32], true); CPubKey pubkey = key.GetPubKey(); CKeyID vchAddress = pubkey.GetID(); return(EncodeDestination(vchAddress)); From b587a18dd3a56cb8807ac549df758cbc7e0012c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 07:26:36 -1100 Subject: [PATCH 234/659] Priv32 --- src/komodo_nSPV_wallet.h | 3 ++- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index bfcb5fecb..2f93ee2d5 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -302,7 +302,8 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a mtx.nExpiryHeight = 0; mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; - mtx.nLockTime = (uint32_t)time(NULL) - 777; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + mtx.nLockTime = (uint32_t)time(NULL) - 777; memset(used,0,sizeof(used)); data.resize(20); memcpy(&data[0],&rmd160[1],20); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3ac705dff..ef511e78d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -186,7 +186,7 @@ UniValue getnewaddress(const UniValue& params, bool fHelp) #else randombytes_buf(priv32,sizeof(priv32)); #endif - key.Set(&priv32[0],&priv[32], true); + key.Set(&priv32[0],&priv32[32], true); CPubKey pubkey = key.GetPubKey(); CKeyID vchAddress = pubkey.GetID(); return(EncodeDestination(vchAddress)); From 94d248033db65464e77c0431bc6ee4d4e2df980e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 07:29:08 -1100 Subject: [PATCH 235/659] Key --- src/wallet/rpcwallet.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ef511e78d..a21ca868e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -180,16 +180,19 @@ UniValue getnewaddress(const UniValue& params, bool fHelp) if ( KOMODO_NSPV != 0 ) { - uint8_t priv32[32]; + UniValue result(UniValue::VOBJ); uint8_t priv32[32]; #ifndef __WIN32 OS_randombytes(priv32,sizeof(priv32)); #else randombytes_buf(priv32,sizeof(priv32)); #endif + CKey key; key.Set(&priv32[0],&priv32[32], true); CPubKey pubkey = key.GetPubKey(); CKeyID vchAddress = pubkey.GetID(); - return(EncodeDestination(vchAddress)); + result.push_back(Pair("address",EncodeDestination(vchAddress))); + result.push_back(Pair("pubkey",HexStr(pubkey))); + return(result); } LOCK2(cs_main, pwalletMain->cs_wallet); From 5982e769966f4455a17992c65cb5e67f41fe4718 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 07:31:25 -1100 Subject: [PATCH 236/659] Allow nSPV getnewaddress --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a21ca868e..9e1cb4784 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -162,7 +162,7 @@ void OS_randombytes(unsigned char *x,long xlen); UniValue getnewaddress(const UniValue& params, bool fHelp) { - if (!EnsureWalletIsAvailable(fHelp)) + if ( KOMODO_NSPV == 0 && !EnsureWalletIsAvailable(fHelp) ) return NullUniValue; if (fHelp || params.size() > 1) From cecf3f5de59e43088a82667caf5310d39ccb595a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 07:34:47 -1100 Subject: [PATCH 237/659] Display wif --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9e1cb4784..1d7768255 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -190,6 +190,7 @@ UniValue getnewaddress(const UniValue& params, bool fHelp) key.Set(&priv32[0],&priv32[32], true); CPubKey pubkey = key.GetPubKey(); CKeyID vchAddress = pubkey.GetID(); + result.push_back(Pair("wif",EncodeSecret(key))); result.push_back(Pair("address",EncodeDestination(vchAddress))); result.push_back(Pair("pubkey",HexStr(pubkey))); return(result); From d3730db5d8b7f60d26d85d29fa811adfc0a88f24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 07:52:38 -1100 Subject: [PATCH 238/659] Prevent crash when displaying interest --- src/rpc/rawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 97544bd06..c9d16a0de 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -374,7 +374,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) + if ( KOMODO_NSPV == 0 && ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->GetHeight()); From a099b3a0256a8375a8b31bb41ad7aec8e91c2d56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 08:05:19 -1100 Subject: [PATCH 239/659] nSPV full nodes to ignore nSPV messages --- src/main.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 098396533..8f54bc71d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7239,15 +7239,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, return false; } } - else if ( (0) ) - { - if ( pfrom->nServices != 0 ) - { - fprintf(stderr,"debug mode, disconnect legacy peer.%d\n",pfrom->id); - pfrom->fDisconnect = true; - return false; - } - } // Mark this node as currently connected, so we update its timestamp later. if (pfrom->fNetworkNode) { LOCK(cs_main); @@ -7445,9 +7436,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } else if (strCommand == "nSPV") { - std::vector payload; - vRecv >> payload; - komodo_nSPVresp(pfrom,payload); + if ( KOMODO_NSPV != 0 ) + { + std::vector payload; + vRecv >> payload; + komodo_nSPVresp(pfrom,payload); + } return(true); } else if ( KOMODO_NSPV != 0 ) @@ -8240,9 +8234,11 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } state.fShouldBan = false; } - komodo_nSPV(pto); if ( KOMODO_NSPV != 0 ) + { + komodo_nSPV(pto); return(true); + } BOOST_FOREACH(const CBlockReject& reject, state.rejects) pto->PushMessage("reject", (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock); state.rejects.clear(); From 912f50a0e456c51f9a7b2dcbc384cb5dd69b4674 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 08:13:37 -1100 Subject: [PATCH 240/659] Autologout 777 --- src/komodo_nSPV_superlite.h | 2 +- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 9a3f459b0..864106b31 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -228,7 +228,7 @@ UniValue NSPV_login(char *wifstr) strncpy(NSPV_wifstr,wifstr,sizeof(NSPV_wifstr)-1); NSPV_logintime = (uint32_t)time(NULL); result.push_back(Pair("result","success")); - result.push_back(Pair("status","wif will expire in 60 seconds")); + result.push_back(Pair("status","wif will expire in 777 seconds")); NSPV_key = DecodeSecret(wifstr); CPubKey pubkey = NSPV_key.GetPubKey(); CKeyID vchAddress = pubkey.GetID(); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 2f93ee2d5..e9703177a 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -20,7 +20,7 @@ // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_spend extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); -#define NSPV_AUTOLOGOUT 60 +#define NSPV_AUTOLOGOUT 777 #define NSPV_BRANCHID 0x76b809bb From 68c31807c383f10916275436c861099b91df36ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 08:50:01 -1100 Subject: [PATCH 241/659] Catch expired wif before assert --- src/komodo_nSPV_wallet.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index e9703177a..22986db04 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -311,6 +311,12 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a if ( NSPV_addinputs(used,mtx,satoshis+txfee,64,NSPV_utxosresult.utxos,NSPV_utxosresult.numutxos) > 0 ) { mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); + if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","wif expired")); + return(result); + } hex = NSPV_signtx(mtx,txfee,opret,used); if ( hex.size() > 0 ) { From 76ca220c937af15bba7b0cf62806e954fbd0ce32 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 08:50:55 -1100 Subject: [PATCH 242/659] +print --- src/komodo_nSPV_superlite.h | 2 +- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 864106b31..916fea8aa 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -32,9 +32,9 @@ CAmount AmountFromValue(const UniValue& value); int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); uint32_t NSPV_lastinfo,NSPV_logintime; +CKey NSPV_key; char NSPV_wifstr[64],NSPV_pubkeystr[67]; std::string NSPV_address; -CKey NSPV_key; struct NSPV_inforesp NSPV_inforesult; struct NSPV_utxosresp NSPV_utxosresult; struct NSPV_spentinfo NSPV_spentresult; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 22986db04..3ebc7523c 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -355,7 +355,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT ) { - fprintf(stderr,"scrub wif from NSPV memory\n"); + fprintf(stderr,"scrub wif and privkey from NSPV memory\n"); memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); memset(&NSPV_key,0,sizeof(NSPV_key)); NSPV_logintime = 0; From b715a05c069479bcf66260dd93ca6de0bbc39c0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 08:56:11 -1100 Subject: [PATCH 243/659] Boost max connections to 8000 --- src/compat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compat.h b/src/compat.h index 44b7dcee2..b0730d1aa 100644 --- a/src/compat.h +++ b/src/compat.h @@ -39,7 +39,7 @@ #ifdef FD_SETSIZE #undef FD_SETSIZE // prevent redefinition compiler warning #endif -#define FD_SETSIZE 1024 // max number of fds in fd_set +#define FD_SETSIZE (8*1024) // max number of fds in fd_set #include // Must be included before mswsock.h and windows.h From c36802edc3bf4227e84bc8ad767295dbb22332c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 09:16:00 -1100 Subject: [PATCH 244/659] +print --- src/init.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index f2335ce38..2ab35fd5c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -976,13 +976,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Make sure enough file descriptors are available int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1); nMaxConnections = GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS); + fprintf(stderr,"nMaxConnections %d\n",nMaxConnections); nMaxConnections = std::max(std::min(nMaxConnections, (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)), 0); int nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS); + fprintf(stderr,"nMaxConnections %d\n",nMaxConnections); if (nFD < MIN_CORE_FILEDESCRIPTORS) return InitError(_("Not enough file descriptors available.")); if (nFD - MIN_CORE_FILEDESCRIPTORS < nMaxConnections) nMaxConnections = nFD - MIN_CORE_FILEDESCRIPTORS; - + fprintf(stderr,"nMaxConnections %d\n",nMaxConnections); // if using block pruning, then disable txindex // also disable the wallet (for now, until SPV support is implemented in wallet) if (GetArg("-prune", 0)) { From d77b5f657c63d4d6a09df85b37e3623b66384cd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 09:19:21 -1100 Subject: [PATCH 245/659] +print --- src/init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 2ab35fd5c..3cc2d8f63 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -976,10 +976,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Make sure enough file descriptors are available int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1); nMaxConnections = GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS); - fprintf(stderr,"nMaxConnections %d\n",nMaxConnections); + //fprintf(stderr,"nMaxConnections %d\n",nMaxConnections); nMaxConnections = std::max(std::min(nMaxConnections, (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)), 0); int nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS); - fprintf(stderr,"nMaxConnections %d\n",nMaxConnections); + fprintf(stderr,"nMaxConnections %d FD_SETSIZE.%d nBind.%d expr.%d \n",nMaxConnections,FD_SETSIZE,nBind,(int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)); if (nFD < MIN_CORE_FILEDESCRIPTORS) return InitError(_("Not enough file descriptors available.")); if (nFD - MIN_CORE_FILEDESCRIPTORS < nMaxConnections) From 1d4be8defb49d0924dbbc26def422b385f26c80e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 09:24:44 -1100 Subject: [PATCH 246/659] Revert FD_SETSIZE --- src/compat.h | 2 +- src/init.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compat.h b/src/compat.h index b0730d1aa..44b7dcee2 100644 --- a/src/compat.h +++ b/src/compat.h @@ -39,7 +39,7 @@ #ifdef FD_SETSIZE #undef FD_SETSIZE // prevent redefinition compiler warning #endif -#define FD_SETSIZE (8*1024) // max number of fds in fd_set +#define FD_SETSIZE 1024 // max number of fds in fd_set #include // Must be included before mswsock.h and windows.h diff --git a/src/init.cpp b/src/init.cpp index 3cc2d8f63..738d94377 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -979,7 +979,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) //fprintf(stderr,"nMaxConnections %d\n",nMaxConnections); nMaxConnections = std::max(std::min(nMaxConnections, (int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)), 0); int nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS); - fprintf(stderr,"nMaxConnections %d FD_SETSIZE.%d nBind.%d expr.%d \n",nMaxConnections,FD_SETSIZE,nBind,(int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)); + //fprintf(stderr,"nMaxConnections %d FD_SETSIZE.%d nBind.%d expr.%d \n",nMaxConnections,FD_SETSIZE,nBind,(int)(FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS)); if (nFD < MIN_CORE_FILEDESCRIPTORS) return InitError(_("Not enough file descriptors available.")); if (nFD - MIN_CORE_FILEDESCRIPTORS < nMaxConnections) From 6e730ec1504d564f4e1431d4da7c8402aaf570c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 09:56:25 -1100 Subject: [PATCH 247/659] +getinfo fields --- src/komodo_nSPV.h | 13 ++++++++++++- src/komodo_nSPV_fullnode.h | 1 - src/komodo_nSPV_superlite.h | 18 +++++++++++------- src/komodo_nSPV_wallet.h | 2 -- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1df9aedf4..18f85a036 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -16,13 +16,24 @@ // todo: // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) + +// determine if it makes sense to be scanning mempool for the utxo/spentinfo requests, maybe can add isspent flag to txproof, or just use getspentinfo if broadcast fails + // validate proofs +// interest calculations are currently just using what is returned, it should calculate it from scratch + +// need to validate incoming data and update only if it is valid and more recent // make sure to sanity check all vector lengths on receipt -// determine if it makes sense to be scanning mempool for the utxo/spentinfo requests #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H +#define NSPV_POLLITERS 15 +#define NSPV_POLLMICROS 100000 +#define NSPV_MAXVINS 64 +#define NSPV_AUTOLOGOUT 777 +#define NSPV_BRANCHID 0x76b809bb + // nSPV defines and struct definitions with serialization and purge functions #define NSPV_INFO 0x00 diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 5a05d01ae..ee837e6ad 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -17,7 +17,6 @@ #ifndef KOMODO_NSPVFULLNODE_H #define KOMODO_NSPVFULLNODE_H -// on fullnode: // NSPV_get... functions need to return the exact serialized length, which is the size of the structure minus size of pointers, plus size of allocated data #include "notarisationdb.h" diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 916fea8aa..71281d087 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -21,12 +21,6 @@ // no caching, no optimizations, no reducing the number of ntzsproofs needed by detecting overlaps, etc. // advantage is that it is simpler to implement and understand to create a design for a more performant version -// interest calculations are currently just using what is returned, it should calculate it from scratch -// need to validate incoming data and update only if it is valid and more recent - -#define NSPV_POLLITERS 15 -#define NSPV_POLLMICROS 100000 -#define NSPV_MAXVINS 64 CAmount AmountFromValue(const UniValue& value); int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); @@ -113,8 +107,18 @@ UniValue NSPV_ntz_json(struct NSPV_ntz *ptr) UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr) { - UniValue result(UniValue::VOBJ); + UniValue result(UniValue::VOBJ); int32_t expiration; uint32_t timestamp = (uint32_t)time(NULL); result.push_back(Pair("result","success")); + if ( NSPV_address.size() != 0 ) + { + result.push_back(Pair("address",NSPV_address)); + result.push_back(Pair("pubkey",NSPV_pubkeystr)); + } + if ( NSPV_logintime != 0 ) + { + expiration = (NSPV_logintime + NSPV_AUTOLOGOUT - timestamp); + result.push_back(Pair("wifexpires",expiration)); + } result.push_back(Pair("height",(int64_t)ptr->height)); result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 3ebc7523c..7db65b60e 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -20,8 +20,6 @@ // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_spend extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); -#define NSPV_AUTOLOGOUT 777 -#define NSPV_BRANCHID 0x76b809bb /*struct NSPV_ntzproofshared From 24b67c623b68c28eb960d332b8360ad2e7205d34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 19:41:55 -1100 Subject: [PATCH 248/659] Small fixes and logout --- src/komodo_nSPV_superlite.h | 18 ++++++++++++++++-- src/komodo_nSPV_wallet.h | 5 +---- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcdump.cpp | 20 +++++++++++++++++--- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 71281d087..f91df8566 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -214,6 +214,17 @@ UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid) return(result); } +UniValue NSPV_logout() +{ + UniValue result(UniValue::VOBJ); + fprintf(stderr,"scrub wif and privkey from NSPV memory\n"); + memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); + memset(&NSPV_key,0,sizeof(NSPV_key)); + NSPV_logintime = 0; + result.push_back(Pair("result","success")); + return(result); +} + UniValue NSPV_login(char *wifstr) { UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0; @@ -229,11 +240,14 @@ UniValue NSPV_login(char *wifstr) return(result); } memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); - strncpy(NSPV_wifstr,wifstr,sizeof(NSPV_wifstr)-1); NSPV_logintime = (uint32_t)time(NULL); + if ( strcmp(NSPV_wifstr,wifstr) != 0 ) + { + strncpy(NSPV_wifstr,wifstr,sizeof(NSPV_wifstr)-1); + NSPV_key = DecodeSecret(wifstr); + } result.push_back(Pair("result","success")); result.push_back(Pair("status","wif will expire in 777 seconds")); - NSPV_key = DecodeSecret(wifstr); CPubKey pubkey = NSPV_key.GetPubKey(); CKeyID vchAddress = pubkey.GetID(); NSPV_address = EncodeDestination(vchAddress); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 7db65b60e..ba70a3b8a 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -353,10 +353,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT ) { - fprintf(stderr,"scrub wif and privkey from NSPV memory\n"); - memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); - memset(&NSPV_key,0,sizeof(NSPV_key)); - NSPV_logintime = 0; + NSPV_logout(); } if ( (pto->nServices & NODE_NSPV) == 0 ) return; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 36e4a8fda..d3e0646ea 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -426,6 +426,7 @@ static const CRPCCommand vRPCCommands[] = { "nSPV", "nspv_txproof", &nspv_txproof, true }, { "nSPV", "nspv_spend", &nspv_spend, true }, { "nSPV", "nspv_broadcast", &nspv_broadcast, true }, + { "nSPV", "nspv_logout", &nspv_logout, true }, // rewards { "rewards", "rewardslist", &rewardslist, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 31da0e32f..35af45a18 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -464,6 +464,7 @@ extern UniValue nspv_hdrsproof(const UniValue& params, bool fHelp); extern UniValue nspv_txproof(const UniValue& params, bool fHelp); extern UniValue nspv_spend(const UniValue& params, bool fHelp); extern UniValue nspv_broadcast(const UniValue& params, bool fHelp); +extern UniValue nspv_logout(const UniValue& params, bool fHelp); extern UniValue getblocksubsidy(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 225d32c80..7069dcaec 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -974,6 +974,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) UniValue NSPV_getinfo_json(); UniValue NSPV_login(char *wifstr); +UniValue NSPV_logout(); UniValue NSPV_addressutxos(char *coinaddr); UniValue NSPV_broadcast(char *hex); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); @@ -991,6 +992,13 @@ UniValue nspv_getinfo(const UniValue& params, bool fHelp) return(NSPV_getinfo_json()); } +UniValue nspv_logout(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() != 0 ) + throw runtime_error("nspv_logout\n"); + return(NSPV_getinfo_logout()); +} + UniValue nspv_login(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 1 ) @@ -1002,9 +1010,15 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 1 ) throw runtime_error("nspv_listunspent address\n"); - if ( params.size() == 0 && NSPV_address.size() != 0 ) - return(NSPV_addressutxos((char *)NSPV_address.c_str())); - return(NSPV_addressutxos((char *)params[0].get_str().c_str())); + if ( params.size() == 0 ) + { + if ( NSPV_address.size() != 0 ) + return(NSPV_addressutxos((char *)NSPV_address.c_str())); + else throw runtime_error("nspv_listunspent address\n"); + } + if ( params.size() == 1 ) + return(NSPV_addressutxos((char *)params[0].get_str().c_str())); + else throw runtime_error("nspv_listunspent address\n"); } UniValue nspv_spentinfo(const UniValue& params, bool fHelp) From 5e741c03f2ef8740de12fd612195acd22e890804 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 19:46:38 -1100 Subject: [PATCH 249/659] Syntax --- src/wallet/rpcdump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 7069dcaec..43cb4f420 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -996,7 +996,7 @@ UniValue nspv_logout(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 0 ) throw runtime_error("nspv_logout\n"); - return(NSPV_getinfo_logout()); + return(NSPV_logout()); } UniValue nspv_login(const UniValue& params, bool fHelp) From 3e334911871c0922111b39082a774638e7bc1b54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 19:49:17 -1100 Subject: [PATCH 250/659] Add status --- src/komodo_nSPV_superlite.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index f91df8566..e12fd7954 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -217,11 +217,13 @@ UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid) UniValue NSPV_logout() { UniValue result(UniValue::VOBJ); - fprintf(stderr,"scrub wif and privkey from NSPV memory\n"); + result.push_back(Pair("result","success")); + if ( NSPV_logintime != 0 ) + fprintf(stderr,"scrub wif and privkey from NSPV memory\n"); + else result.push_back(Pair("status","wasnt logged in")); memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); memset(&NSPV_key,0,sizeof(NSPV_key)); NSPV_logintime = 0; - result.push_back(Pair("result","success")); return(result); } From 8cde0ef5e4ef61e74181f35c969461b2c2ad2edb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 19:56:29 -1100 Subject: [PATCH 251/659] +print --- src/komodo_nSPV_superlite.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index e12fd7954..8d3124faf 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -289,6 +289,7 @@ UniValue NSPV_getinfo_json() UniValue NSPV_addressutxos(char *coinaddr) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,slen,len = 0; + fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); if ( bitcoin_base58decode(msg,coinaddr) != 25 ) { result.push_back(Pair("result","error")); From 87f816960367fdc344cdfecf78749bdf62c6f32d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 20:01:00 -1100 Subject: [PATCH 252/659] Prevent returning cached inspects --- src/komodo_nSPV_superlite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 8d3124faf..ebafb186c 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -289,7 +289,7 @@ UniValue NSPV_getinfo_json() UniValue NSPV_addressutxos(char *coinaddr) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,slen,len = 0; - fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); + //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); if ( bitcoin_base58decode(msg,coinaddr) != 25 ) { result.push_back(Pair("result","error")); @@ -312,7 +312,7 @@ UniValue NSPV_addressutxos(char *coinaddr) for (i=0; i= NSPV_inforesult.height ) + if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); } } From b948cd45de3e5ef2cb460db2648627e8f10344fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 20:55:20 -1100 Subject: [PATCH 253/659] +prints --- src/komodo_nSPV_fullnode.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index ee837e6ad..e4e8f7518 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -200,11 +200,12 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int ptr->retcode = 0; rawdata.resize(n); memcpy(&rawdata[0],data,n); + fprintf(stderr,"sendraw.(%s)\n",HexStr(rawdata)); if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) { LOCK(cs_main); ptr->txid = tx.GetHash(); - //fprintf(stderr,"addmempool transaction %s\n",ptr->txid.GetHex().c_str()); + fprintf(stderr,"addmempool transaction %s\n",ptr->txid.GetHex().c_str()); if ( myAddtomempool(tx) != 0 ) ptr->retcode = 1; else ptr->retcode = 0; From b9e7f023ae47925b58f8e07546ac9eca6f526731 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 20:57:12 -1100 Subject: [PATCH 254/659] c_str --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index e4e8f7518..b93e299f1 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -200,7 +200,7 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int ptr->retcode = 0; rawdata.resize(n); memcpy(&rawdata[0],data,n); - fprintf(stderr,"sendraw.(%s)\n",HexStr(rawdata)); + fprintf(stderr,"sendraw.(%s)\n",HexStr(rawdata).c_str()); if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) { LOCK(cs_main); From 6deebc41c792b9ea2efc2ac8978188b48a2bb5d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 21:09:34 -1100 Subject: [PATCH 255/659] +print --- src/komodo_nSPV_wallet.h | 14 +++++++++++--- src/wallet/rpcdump.cpp | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index ba70a3b8a..5c34bcb14 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -40,15 +40,23 @@ struct NSPV_ntzsproofresp int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) { - int32_t i; - // verify nextntz is valid notarization - // validate blockhash of lasthdr with nextntz value, and height + /* int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; + if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) + return(-1); + else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid) < 0 ) + return(-2); + else if ( NSPV_doublesha256(&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) + return(-3); for (i=ptr->common.numhdrs-1; i>0; i--) { // make sure the hash of i-1 matches the prevBlockhash of i } // verify prevntz is valid notarization // verify blockhash of first hdr with prevntz value and height + if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) + return(-1); + else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid) < 0 ) + return(-2);*/ return(0); } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 43cb4f420..d5bc66209 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1068,6 +1068,7 @@ UniValue nspv_spend(const UniValue& params, bool fHelp) if ( NSPV_address.size() == 0 ) throw runtime_error("to nspv_send you need an active nspv_login\n"); satoshis = atof(params[1].get_str().c_str())*COIN + 0.0000000049; + fprintf(stderr,"satoshis.%lld from %.8f\n",(long long)satoshis,atof(params[1].get_str().c_str())); if ( satoshis < 1000 ) throw runtime_error("amount too small\n"); return(NSPV_spend((char *)NSPV_address.c_str(),(char *)params[0].get_str().c_str(),satoshis)); From 50120563347dffe613df9807e409fff21d173a94 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 21:38:58 -1100 Subject: [PATCH 256/659] Patch --- src/komodo_nSPV.h | 27 ++++++++++++++++ src/komodo_nSPV_fullnode.h | 31 +++--------------- src/komodo_nSPV_wallet.h | 65 ++++++++++++++++---------------------- 3 files changed, 60 insertions(+), 63 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 18f85a036..31756881f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -374,6 +374,8 @@ void NSPV_broadcast_purge(struct NSPV_broadcastresp *ptr) memset(ptr,0,sizeof(*ptr)); } +// useful utility functions + uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) { bits256 _hash; uint256 hash; int32_t i; @@ -383,4 +385,29 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) return(hash); } +int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) +{ + std::vector rawdata; + rawdata.resize(datalen); + memcpy(&rawdata[0],data,datalen); + if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) + return(0); + else return(-1); +} + +uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret) +{ + uint256 desttxid; int32_t i; + iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); + for (i=0; i<32; i++) + ((uint8_t *)blockhashp)[i] = opret[4 + i]; + for (i=0; i<32; i++) + ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; + return(desttxid); +} + +int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *txidp,int32_t *txidhtp,uint256 *desttxidp,CTransaction tx) +{ + return(0); +} #endif // KOMODO_NSPV_H diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index b93e299f1..fb45bd4f5 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -35,27 +35,9 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) return(txid); } -uint256 NSPV_extract_desttxid(int32_t *heightp,char *symbol,std::vector opret) -{ - uint256 desttxid; int32_t i; - //for (i=0; i<32; i++) - // fprintf(stderr,"%02x",opret[i]); - //fprintf(stderr," blockhash, "); - //for (i=0; i<4; i++) - // fprintf(stderr,"%02x",opret[32+i]); - //fprintf(stderr," height, "); - iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); - //for (i=0; i<32; i++) - // fprintf(stderr,"%02x",opret[36+i]); - //fprintf(stderr," desttxid\n"); - for (i=0; i<32; i++) - ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; - return(desttxid); -} - int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) { - int32_t txidht; Notarisation nota; char *symbol; + int32_t txidht; Notarisation nota; char *symbol; uint256 bhash; symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(txids,0,sizeof(*txids)*2); memset(desttxids,0,sizeof(*desttxids)*2); @@ -65,7 +47,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des return(-1); txids[0] = nota.first; txidhts[0] = txidht; - desttxids[0] = NSPV_extract_desttxid(&ntzheights[0],symbol,E_MARSHAL(ss << nota.second)); + desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash,symbol,E_MARSHAL(ss << nota.second)); //if ( height != 2668 ) // fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); if ( ntzheights[0] == height-1 ) // offset the +1 from caller @@ -80,7 +62,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des { txids[1] = nota.first; txidhts[1] = txidht; - desttxids[1] = NSPV_extract_desttxid(&ntzheights[1],symbol,E_MARSHAL(ss << nota.second)); + desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash,symbol,E_MARSHAL(ss << nota.second)); } return(0); } @@ -196,12 +178,9 @@ uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int32_t n) { - CTransaction tx; std::vector rawdata; + CTransaction tx; ptr->retcode = 0; - rawdata.resize(n); - memcpy(&rawdata[0],data,n); - fprintf(stderr,"sendraw.(%s)\n",HexStr(rawdata).c_str()); - if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) + if ( NSPV_txextract(tx,data,n) == 0 ) { LOCK(cs_main); ptr->txid = tx.GetHash(); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 5c34bcb14..ac3b22963 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -20,70 +20,61 @@ // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_spend extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); - - -/*struct NSPV_ntzproofshared -{ - struct NSPV_equihdr *hdrs; - int32_t prevht,nextht,pad32; - uint16_t numhdrs,pad16; -}; - -struct NSPV_ntzsproofresp -{ - struct NSPV_ntzproofshared common; - uint256 prevtxid,nexttxid; - int32_t pad32,prevtxidht,nexttxidht; - uint16_t prevtxlen,nexttxlen; - uint8_t *prevntz,*nextntz; -};*/ - int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) { - /* int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; - if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) + int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; + if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) return(-1); - else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid) < 0 ) + else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) return(-2); - else if ( NSPV_doublesha256(&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) + else if ( tx.GetHash() != ptr->nexttxid ) return(-3); + else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid,tx) < 0 ) + return(-4); + else if ( height != ptr->common.nextht ) + return(-5); + else if ( NSPV_doublesha256(&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) + return(-6); for (i=ptr->common.numhdrs-1; i>0; i--) { - // make sure the hash of i-1 matches the prevBlockhash of i + if ( NSPV_doublesha256(&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)) != ptr->common.hdrs.prevblockhash ) + return(-i-11); } - // verify prevntz is valid notarization - // verify blockhash of first hdr with prevntz value and height if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) - return(-1); - else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid) < 0 ) - return(-2);*/ + return(-6); + else if ( tx.GetHash() != ptr->prevtxid ) + return(-7); + else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid,tx) < 0 ) + return(-8); + else if ( height != ptr->common.prevht ) + return(-9); + else if ( NSPV_doublesha256(&ptr->common.hdrs[0],sizeof(*ptr->common.hdrs)) != blockhash ) + return(-10); return(0); } int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) { - char *txstr; int32_t retval = 0; + int32_t retval = 0; NSPV_txproof(txid,height); - if ( NSPV_txproofresult.txid != txid || NSPV_txproofresult.height != height ) + if ( NSPV_txproofresult.txid != txid ) return(-1); - txstr = (char *)malloc(NSPV_txproofresult.txlen*2 + 1); - init_hexbytes_noT(txstr,NSPV_txproofresult.tx,NSPV_txproofresult.txlen); - if ( !DecodeHexTx(tx,txstr) ) - retval = -1; + if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 ) + retval = -20; else { NSPV_notarizations(height); // gets the prev and next notarizations if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) { NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment - if ( NSPV_validatehdrs(&NSPV_ntzsproofresult) == 0 ) + if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { // merkle prove txproof to the merkleroot in the corresponding hdr } } else retval = -1; } - free(txstr); - return(retval); + fprintf(stderr,"NSPV_gettransaction retval would have been %d\n",retval); + return(0); } int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) From 674ebb06cdd0836d31ae06c4625a0e6f1f77ab5c Mon Sep 17 00:00:00 2001 From: TonyL Date: Sun, 7 Jul 2019 11:40:57 +0300 Subject: [PATCH 257/659] nspv client rpc calls unittest --- qa/rpc-tests/src/nspv_client_test.py | 114 +++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 qa/rpc-tests/src/nspv_client_test.py diff --git a/qa/rpc-tests/src/nspv_client_test.py b/qa/rpc-tests/src/nspv_client_test.py new file mode 100644 index 000000000..fbf0e5360 --- /dev/null +++ b/qa/rpc-tests/src/nspv_client_test.py @@ -0,0 +1,114 @@ +import sys +sys.path.append('../../src/tui') + +from lib import tuilib +import unittest + +''' +specify chain ticker (daemon should be up), wif which will be imported and address to which you want to broadcast +added 1 second sleep after each case to surely not face the nSPV server limitation (1 call/second) +''' + +wif = '' +dest_address = 'RMjy5VkHFJkXTJDTJ3XX1zVzukP48sKyva' +amount = '0.1' +chain = 'ILN' + +rpc_proxy = tuilib.def_credentials(chain) + + +class TestNspvClient(unittest.TestCase): + + def test_nspv_getinfo(self): + print("testing nspv_getinfo") + result = rpc_proxy.nspv_getinfo() + self.assertEqual(result["result"], "success") + self.assertGreater(result["height"], 2689) + time.sleep(1) + + def test_nspv_notarizations(self): + print("testing nspv_notarizations") + result = rpc_proxy.nspv_notarizations("2000") + self.assertEqual(result["result"], "success") + self.assertEqual(result["prev"]["notarized_height"], 1998) + self.assertEqual(result["next"]["notarized_height"], 2002) + time.sleep(1) + + def test_nspv_hdrsproof(self): + print("testing nspv_hdrsproof") + result = rpc_proxy.nspv_hdrsproof("2000", "2100") + self.assertEqual(result["result"], "success") + self.assertEqual(result["numhdrs"], 101) + time.sleep(1) + + def test_nspv_login(self): + print("testing nspv_login") + result = rpc_proxy.nspv_login(wif) + self.assertEqual(result["result"], "success") + self.assertEqual(result["status"], "wif will expire in 777 seconds") + time.sleep(1) + + def test_nspv_listunspent(self): + print("testing nspv_listunspent") + result = rpc_proxy.nspv_listunspent() + self.assertEqual(result["result"], "success") + time.sleep(1) + result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT") + self.assertEqual(result["result"], "error") + + def test_nspv_spend(self): + print("testing nspv_spend") + result = rpc_proxy.nspv_login(wif) + result = rpc_proxy.nspv_spend(dest_address, amount) + self.assertEqual(result["result"], "success") + self.assertEqual(result["vout"][0]["valueZat"], 10000000) + time.sleep(1) + + def test_nspv_broadcast(self): + print("testing nspv_broadcast") + result = rpc_proxy.nspv_login(wif) + broadcast_hex = rpc_proxy.nspv_spend(dest_address, amount)["hex"] + time.sleep(1) + result = rpc_proxy.nspv_broadcast(broadcast_hex) + self.assertEqual(result["result"], "success") + self.assertEqual(result["retcode"], 1) + self.assertEqual(result["expected"], result["broadcast"]) + print("Broadcast txid: " + result["broadcast"]) + time.sleep(1) + + def test_nspv_logout(self): + print("testing nspv_logout") + rpc_proxy.nspv_login(wif) + time.sleep(1) + rpc_proxy.nspv_logout() + time.sleep(1) + result = rpc_proxy.nspv_spend(dest_address, amount) + self.assertEqual(result["result"], "error") + self.assertEqual(result["error"], "wif expired") + time.sleep(1) + + def test_nspv_spentinfo(self): + print("testing nspv_spent_info") + result = rpc_proxy.nspv_spentinfo("67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418", "1") + self.assertEqual(result["result"], "success") + self.assertEqual(result["spentheight"], 2681) + time.sleep(1) + + def test_nspv_txproof(self): + print("testing nspv_txproof") + result = rpc_proxy.nspv_txproof("67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418", "2673") + self.assertEqual(result["txid"], "67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418") + time.sleep(1) + + def test_nspv_login_timout(self): + print("testing auto-logout in 777 seconds") + rpc_proxy.nspv_login(wif) + time.sleep(777) + result = rpc_proxy.nspv_spend(dest_address, amount) + self.assertEqual(result["result"], "error") + self.assertEqual(result["error"], "wif expired") + time.sleep(1) + + +if __name__ == '__main__': + unittest.main() From 60ea15808ae78d6b63fb23af0938c85c87768bba Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 21:41:03 -1100 Subject: [PATCH 258/659] Void --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 31756881f..c7c8e6d70 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -376,7 +376,7 @@ void NSPV_broadcast_purge(struct NSPV_broadcastresp *ptr) // useful utility functions -uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) +uint256 NSPV_doublesha256(void *data,int32_t datalen) { bits256 _hash; uint256 hash; int32_t i; _hash = bits256_doublesha256(0,data,datalen); From 27d4e82f0cfa908cdd3e2e3c0123c95ec6997406 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 21:42:31 -1100 Subject: [PATCH 259/659] (uint8_t *) --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_wallet.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c7c8e6d70..31756881f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -376,7 +376,7 @@ void NSPV_broadcast_purge(struct NSPV_broadcastresp *ptr) // useful utility functions -uint256 NSPV_doublesha256(void *data,int32_t datalen) +uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) { bits256 _hash; uint256 hash; int32_t i; _hash = bits256_doublesha256(0,data,datalen); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index ac3b22963..00b1b27ec 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -33,11 +33,11 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-4); else if ( height != ptr->common.nextht ) return(-5); - else if ( NSPV_doublesha256(&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) + else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) return(-6); for (i=ptr->common.numhdrs-1; i>0; i--) { - if ( NSPV_doublesha256(&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)) != ptr->common.hdrs.prevblockhash ) + if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)) != ptr->common.hdrs.prevblockhash ) return(-i-11); } if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) @@ -48,7 +48,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-8); else if ( height != ptr->common.prevht ) return(-9); - else if ( NSPV_doublesha256(&ptr->common.hdrs[0],sizeof(*ptr->common.hdrs)) != blockhash ) + else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[0],sizeof(*ptr->common.hdrs)) != blockhash ) return(-10); return(0); } From 0d45abf20f040b9bf7202bb8a3125e173a42a6ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 21:44:01 -1100 Subject: [PATCH 260/659] hashPrevBlock --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 31756881f..c0c45d8e2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -379,7 +379,7 @@ void NSPV_broadcast_purge(struct NSPV_broadcastresp *ptr) uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) { bits256 _hash; uint256 hash; int32_t i; - _hash = bits256_doublesha256(0,data,datalen); + _hash = bits256_doublesha256(0,(void *)data,datalen); for (i=0; i<32; i++) ((uint8_t *)&hash)[i] = _hash.bytes[31 - i]; return(hash); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 00b1b27ec..081af7b05 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -37,7 +37,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-6); for (i=ptr->common.numhdrs-1; i>0; i--) { - if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)) != ptr->common.hdrs.prevblockhash ) + if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)) != ptr->common.hdrs.hashPrevBlock ) return(-i-11); } if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) From c7f68f34e7be93da3b4946b5fc7de57b06122c0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 21:45:19 -1100 Subject: [PATCH 261/659] [I] --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 081af7b05..ab0007571 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -37,7 +37,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-6); for (i=ptr->common.numhdrs-1; i>0; i--) { - if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)) != ptr->common.hdrs.hashPrevBlock ) + if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)) != ptr->common.hdrs[i].hashPrevBlock ) return(-i-11); } if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) From 79ac3e8bac4490c2f890c4868fddf83abe530804 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 21:46:56 -1100 Subject: [PATCH 262/659] - --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c0c45d8e2..31756881f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -379,7 +379,7 @@ void NSPV_broadcast_purge(struct NSPV_broadcastresp *ptr) uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) { bits256 _hash; uint256 hash; int32_t i; - _hash = bits256_doublesha256(0,(void *)data,datalen); + _hash = bits256_doublesha256(0,data,datalen); for (i=0; i<32; i++) ((uint8_t *)&hash)[i] = _hash.bytes[31 - i]; return(hash); From 2d5a19ef66ce5cbc8e73143995d5f40c4302cd1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 21:51:18 -1100 Subject: [PATCH 263/659] Test non-not validation --- src/komodo_nSPV_wallet.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index ab0007571..d6ef904af 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -31,10 +31,10 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-3); else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid,tx) < 0 ) return(-4); - else if ( height != ptr->common.nextht ) - return(-5); - else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) - return(-6); + //else if ( height != ptr->common.nextht ) + // return(-5); + //else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) + // return(-6); for (i=ptr->common.numhdrs-1; i>0; i--) { if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)) != ptr->common.hdrs[i].hashPrevBlock ) @@ -46,10 +46,10 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-7); else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid,tx) < 0 ) return(-8); - else if ( height != ptr->common.prevht ) - return(-9); - else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[0],sizeof(*ptr->common.hdrs)) != blockhash ) - return(-10); + //else if ( height != ptr->common.prevht ) + // return(-9); + //else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[0],sizeof(*ptr->common.hdrs)) != blockhash ) + // return(-10); return(0); } From 386c1b8ced5ce8b78efcfd89d501c9be0bbd0c93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 21:55:46 -1100 Subject: [PATCH 264/659] +field --- src/komodo_nSPV_superlite.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index ebafb186c..d404d3f64 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -165,15 +165,18 @@ UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr) return(result); } -UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs) +UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs,int32_t height) { UniValue array(UniValue::VARR); int32_t i; for (i=0; inexttxidht)); result.push_back(Pair("nexttxlen",(int64_t)ptr->prevtxlen)); result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); - result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs))); + result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); return(result); } From cff0f5ea4e098bd03ffc60eb4329ee57be513c6e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:06:05 -1100 Subject: [PATCH 265/659] Print block hash --- src/komodo_nSPV_wallet.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index d6ef904af..3a9b2b5cc 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -37,7 +37,9 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) // return(-6); for (i=ptr->common.numhdrs-1; i>0; i--) { - if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)) != ptr->common.hdrs[i].hashPrevBlock ) + blockhash = NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)); + fprintf(stderr,"i.%d ht.%d blockhash.%s vs [i+1].prev %s\n",i-1,ptr->common.prevht+i-1,blockhash.GetHex().c_str(),ptr->common.hdrs[i].hashPrevBlock.GetHex().c_str()); + if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) return(-i-11); } if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) From b3a982b391f84dd8931bdd6905e32e77bf487fb4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:11:24 -1100 Subject: [PATCH 266/659] Test --- src/komodo_nSPV_wallet.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 3a9b2b5cc..15ac01cd0 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -23,6 +23,7 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) { int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; + fprintf(stderr,"NSPV_validatehdrs.%d\n",ptr->common.numhdrs); if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) return(-1); else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) @@ -35,13 +36,15 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) // return(-5); //else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) // return(-6); + fprintf(stderr,"numhdrs.%d\n",ptr->common.numhdrs); for (i=ptr->common.numhdrs-1; i>0; i--) { - blockhash = NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[i-1],sizeof(*ptr->common.hdrs)); + blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); fprintf(stderr,"i.%d ht.%d blockhash.%s vs [i+1].prev %s\n",i-1,ptr->common.prevht+i-1,blockhash.GetHex().c_str(),ptr->common.hdrs[i].hashPrevBlock.GetHex().c_str()); if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) return(-i-11); } + fprintf(stderr,"i.%d\n",i); if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) return(-6); else if ( tx.GetHash() != ptr->prevtxid ) From 1be923d1cfb6c618a759fb98adbfb37185e3a71c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:15:22 -1100 Subject: [PATCH 267/659] NSPV_hdrhash --- src/komodo_nSPV.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 31756881f..2bc3dacc3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -385,6 +385,13 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) return(hash); } +uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) +{ + uint8_t data[sizeof(*hdr)]; uint16_t hdrsize = sizeof(*hdr); + iguana_rwequihdrvec(1,data,&hdrsize,&hdr) + return(NSPV_doublesha256(data,sizeof(*hdr))); +} + int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) { std::vector rawdata; From 5e05f1d467e3729cb5a7dddebc25a1f42e53ca0f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:16:13 -1100 Subject: [PATCH 268/659] ; --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 2bc3dacc3..4250c948c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -388,7 +388,7 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) { uint8_t data[sizeof(*hdr)]; uint16_t hdrsize = sizeof(*hdr); - iguana_rwequihdrvec(1,data,&hdrsize,&hdr) + iguana_rwequihdrvec(1,data,&hdrsize,&hdr); return(NSPV_doublesha256(data,sizeof(*hdr))); } From 52ade7db42e8383741ef8ceb3e09ef4031fc5e0b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:25:13 -1100 Subject: [PATCH 269/659] Test --- src/komodo_nSPV_fullnode.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index fb45bd4f5..bae0870ce 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -264,9 +264,11 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 ptr->common.nextht = nextht; ptr->common.numhdrs = (nextht - prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); - //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); + fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); for (i=0; icommon.numhdrs; i++) { + hashBlock = NSPV_hdrhash(&ptr->common.hdrs[i]); + fprintf(stderr,"hdr[%d] %s\n",prevht+i,hashBlock.GetHex().c_str()); if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) { fprintf(stderr,"error setting hdr.%d\n",prevht+i); @@ -279,7 +281,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid); ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid); - //fprintf(stderr,"prevtxlen.%d nexttxlen.%d size %ld -> %ld\n",ptr->prevtxlen,ptr->nexttxlen,sizeof(*ptr),sizeof(*ptr) - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevlen + ptr->nextlen); + fprintf(stderr,"ptr->prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevtxlen + ptr->nexttxlen); } From 5679aa0247b04b8d2f58bd32a51c415429ea72dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:42:08 -1100 Subject: [PATCH 270/659] Redo block hash --- src/komodo_nSPV.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4250c948c..a0bebdb19 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -387,9 +387,16 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) { - uint8_t data[sizeof(*hdr)]; uint16_t hdrsize = sizeof(*hdr); - iguana_rwequihdrvec(1,data,&hdrsize,&hdr); - return(NSPV_doublesha256(data,sizeof(*hdr))); + CBlockIndex block; + block.nVersion = hdr->nVersion; + block.hashPrevBlock = hdr->hashPrevBlock; + block.hashMerkleRoot = hdr->hashMerkleRoot; + block.hashFinalSaplingRoot = hdr->hashFinalSaplingRoot; + block.nTime = hdr->nTime; + block.nBits = hdr->nBits; + block.nNonce = hdr->nNonce; + memcpy(block.nSolution,hdr->nSolution,sizeof(hdr->nSolution)); + return(block.GetHash()); } int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) From f0038e1d009dffa908de295d5a73720161dceddf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:45:40 -1100 Subject: [PATCH 271/659] Syntax --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a0bebdb19..8bf0d7a37 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -387,7 +387,7 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) { - CBlockIndex block; + CBlockHeader block; block.nVersion = hdr->nVersion; block.hashPrevBlock = hdr->hashPrevBlock; block.hashMerkleRoot = hdr->hashMerkleRoot; From 27cb736a2f8b89b11afc06ae826ed49d353a2217 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:46:58 -1100 Subject: [PATCH 272/659] &[0] --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 8bf0d7a37..1d94dddd7 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -395,7 +395,7 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) block.nTime = hdr->nTime; block.nBits = hdr->nBits; block.nNonce = hdr->nNonce; - memcpy(block.nSolution,hdr->nSolution,sizeof(hdr->nSolution)); + memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution)); return(block.GetHash()); } From 6994f4195169f3d5f103061b3785209f1cd05a9a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:51:08 -1100 Subject: [PATCH 273/659] +print --- src/komodo_nSPV.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1d94dddd7..74e64d83d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -387,7 +387,7 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) { - CBlockHeader block; + CBlockHeader block; uint256 blockhash; uint8_t data[sizeof(*hdr)]; block.nVersion = hdr->nVersion; block.hashPrevBlock = hdr->hashPrevBlock; block.hashMerkleRoot = hdr->hashMerkleRoot; @@ -396,6 +396,8 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) block.nBits = hdr->nBits; block.nNonce = hdr->nNonce; memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution)); + blockhash = NSPV_doublesha256(data,sizeof(*hdr)); + fprintf(stderr,"blockhash.%s vs %s\n",blockhash.GetHex().c_str(),block.GetHash().GetHex().c_str()); return(block.GetHash()); } From 00aad8e85350dfc75c77c1bcaa893fcd30e7fbfb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:53:42 -1100 Subject: [PATCH 274/659] Use function --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d404d3f64..745f4e85e 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -172,7 +172,7 @@ UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs,int32_t hei { UniValue item(UniValue::VOBJ); item.push_back(Pair("height",(int64_t)height+i)); - item.push_back(Pair("blockhash",NSPV_doublesha256((uint8_t *)&hdrs[i],sizeof(hdrs[i])).GetHex())); + item.push_back(Pair("blockhash",NSPV_hdrhash(&hdrs[i]))); item.push_back(Pair("hashPrevBlock",hdrs[i].hashPrevBlock.GetHex())); item.push_back(Pair("hashMerkleRoot",hdrs[i].hashMerkleRoot.GetHex())); item.push_back(Pair("nTime",(int64_t)hdrs[i].nTime)); From 0bc975c33afeedbbff3472f85a2ff6f057b69052 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:54:40 -1100 Subject: [PATCH 275/659] Gather --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 745f4e85e..21d0c1bc0 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -172,7 +172,7 @@ UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs,int32_t hei { UniValue item(UniValue::VOBJ); item.push_back(Pair("height",(int64_t)height+i)); - item.push_back(Pair("blockhash",NSPV_hdrhash(&hdrs[i]))); + item.push_back(Pair("blockhash",NSPV_hdrhash(&hdrs[i]).GetHex())); item.push_back(Pair("hashPrevBlock",hdrs[i].hashPrevBlock.GetHex())); item.push_back(Pair("hashMerkleRoot",hdrs[i].hashMerkleRoot.GetHex())); item.push_back(Pair("nTime",(int64_t)hdrs[i].nTime)); From a84ce71083dec32c68976e1fed3bb6fdd5658397 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 22:57:50 -1100 Subject: [PATCH 276/659] Simplify --- src/komodo_nSPV.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 74e64d83d..40b18f064 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -387,7 +387,8 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) { - CBlockHeader block; uint256 blockhash; uint8_t data[sizeof(*hdr)]; + uint256 blockhash; uint8_t data[sizeof(*hdr)]; uint16_t datalen = sizeof(*hdr); + /*CBlockHeader block; block.nVersion = hdr->nVersion; block.hashPrevBlock = hdr->hashPrevBlock; block.hashMerkleRoot = hdr->hashMerkleRoot; @@ -395,10 +396,11 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) block.nTime = hdr->nTime; block.nBits = hdr->nBits; block.nNonce = hdr->nNonce; - memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution)); + memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution));*/ + iguana_rwequihdrvec(1,data,&datalen,&hdr); blockhash = NSPV_doublesha256(data,sizeof(*hdr)); - fprintf(stderr,"blockhash.%s vs %s\n",blockhash.GetHex().c_str(),block.GetHash().GetHex().c_str()); - return(block.GetHash()); + return(blockhash); + //return(block.GetHash()); } int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) From c80721db9c5e5f5545ff046c6d50a056e2667420 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:01:51 -1100 Subject: [PATCH 277/659] Use proper functions --- src/komodo_nSPV.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 40b18f064..2b98bb313 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -387,7 +387,7 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) { - uint256 blockhash; uint8_t data[sizeof(*hdr)]; uint16_t datalen = sizeof(*hdr); + uint256 blockhash; uint8_t data[sizeof(*hdr)]; /*CBlockHeader block; block.nVersion = hdr->nVersion; block.hashPrevBlock = hdr->hashPrevBlock; @@ -397,8 +397,8 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) block.nBits = hdr->nBits; block.nNonce = hdr->nNonce; memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution));*/ - iguana_rwequihdrvec(1,data,&datalen,&hdr); - blockhash = NSPV_doublesha256(data,sizeof(*hdr)); + n = NSPV_rwequihdr(1,data,hdr); + blockhash = NSPV_doublesha256(data,sizeof(data)); return(blockhash); //return(block.GetHash()); } From 295f6a04d65d60eaa66f2c12c4b2b56a872865e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:02:45 -1100 Subject: [PATCH 278/659] Syntax --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 2b98bb313..b9f86cc83 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -397,7 +397,7 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) block.nBits = hdr->nBits; block.nNonce = hdr->nNonce; memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution));*/ - n = NSPV_rwequihdr(1,data,hdr); + NSPV_rwequihdr(1,data,hdr); blockhash = NSPV_doublesha256(data,sizeof(data)); return(blockhash); //return(block.GetHash()); From caaedc37ced6ad09a93db7dfe7c88105112e4685 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:05:22 -1100 Subject: [PATCH 279/659] block.hash --- src/komodo_nSPV.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b9f86cc83..46db622c3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -388,7 +388,7 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) { uint256 blockhash; uint8_t data[sizeof(*hdr)]; - /*CBlockHeader block; + CBlockHeader block; block.nVersion = hdr->nVersion; block.hashPrevBlock = hdr->hashPrevBlock; block.hashMerkleRoot = hdr->hashMerkleRoot; @@ -396,11 +396,12 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) block.nTime = hdr->nTime; block.nBits = hdr->nBits; block.nNonce = hdr->nNonce; - memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution));*/ + memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution)); NSPV_rwequihdr(1,data,hdr); blockhash = NSPV_doublesha256(data,sizeof(data)); - return(blockhash); - //return(block.GetHash()); + fprintf(stderr,"%s vs block %s\n",blockhash.GetHex().c_str(),block.GetHash().GetHex().c_str()); + //return(blockhash); + return(block.GetHash()); } int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) From a31beda7771db9b8f1fef0afa8e2398d75df91a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:09:30 -1100 Subject: [PATCH 280/659] Alloc space --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 46db622c3..47976f1be 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -396,6 +396,7 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) block.nTime = hdr->nTime; block.nBits = hdr->nBits; block.nNonce = hdr->nNonce; + block.nSolution.resize(sizeof(hdr->nSolution)); memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution)); NSPV_rwequihdr(1,data,hdr); blockhash = NSPV_doublesha256(data,sizeof(data)); From 076ee43baeddca07abfb59de67b10f9519d9446c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:13:08 -1100 Subject: [PATCH 281/659] -print --- src/komodo_nSPV.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 47976f1be..9d00d0ba6 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -387,7 +387,6 @@ uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) { - uint256 blockhash; uint8_t data[sizeof(*hdr)]; CBlockHeader block; block.nVersion = hdr->nVersion; block.hashPrevBlock = hdr->hashPrevBlock; @@ -398,10 +397,6 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) block.nNonce = hdr->nNonce; block.nSolution.resize(sizeof(hdr->nSolution)); memcpy(&block.nSolution[0],hdr->nSolution,sizeof(hdr->nSolution)); - NSPV_rwequihdr(1,data,hdr); - blockhash = NSPV_doublesha256(data,sizeof(data)); - fprintf(stderr,"%s vs block %s\n",blockhash.GetHex().c_str(),block.GetHash().GetHex().c_str()); - //return(blockhash); return(block.GetHash()); } From b29d20a9b421df3db3af2278e81cad9af1a44436 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:15:58 -1100 Subject: [PATCH 282/659] Test --- src/komodo_nSPV_superlite.h | 2 +- src/komodo_nSPV_wallet.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 21d0c1bc0..597ed3800 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -460,7 +460,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_NTZSRESP: NSPV_ntzsresp_purge(&NSPV_ntzsresult); NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); - fprintf(stderr,"got ntzs response %u size.%d\n",timestamp,(int32_t)response.size()); + fprintf(stderr,"got ntzs response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); break; case NSPV_NTZSPROOFRESP: NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 15ac01cd0..1065224c9 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -71,6 +71,7 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) NSPV_notarizations(height); // gets the prev and next notarizations if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) { + fprintf(stderr,"gettx prev.%d next.%d\n",NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { From ec8c41e79259c435fcbe0a5c8eacd4bb522ab59d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:28:23 -1100 Subject: [PATCH 283/659] Test --- src/komodo_nSPV_superlite.h | 2 +- src/komodo_nSPV_wallet.h | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 597ed3800..97c0dc1c2 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -470,7 +470,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_TXPROOFRESP: NSPV_txproof_purge(&NSPV_txproofresult); NSPV_rwtxproof(0,&response[1],&NSPV_txproofresult); - fprintf(stderr,"got txproof response %u size.%d\n",timestamp,(int32_t)response.size()); + fprintf(stderr,"got txproof response %u size.%d %s ht.%d\n",timestamp,(int32_t)response.size(),NSPV_txproofresult.txid.GetHex().c_str(),NSPV_txproofresult.height); break; case NSPV_SPENTINFORESP: NSPV_spentinfo_purge(&NSPV_spentresult); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 1065224c9..8559293c4 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -23,7 +23,6 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) { int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; - fprintf(stderr,"NSPV_validatehdrs.%d\n",ptr->common.numhdrs); if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) return(-1); else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) @@ -40,11 +39,9 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) for (i=ptr->common.numhdrs-1; i>0; i--) { blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); - fprintf(stderr,"i.%d ht.%d blockhash.%s vs [i+1].prev %s\n",i-1,ptr->common.prevht+i-1,blockhash.GetHex().c_str(),ptr->common.hdrs[i].hashPrevBlock.GetHex().c_str()); if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) return(-i-11); } - fprintf(stderr,"i.%d\n",i); if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) return(-6); else if ( tx.GetHash() != ptr->prevtxid ) @@ -71,12 +68,15 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) NSPV_notarizations(height); // gets the prev and next notarizations if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) { - fprintf(stderr,"gettx prev.%d next.%d\n",NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); - NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment - if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) + fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); + if ( NSPV_ntzsresult.prevntz.height <= height && height <= NSPV_ntzsresult.nextntz.height ) { - // merkle prove txproof to the merkleroot in the corresponding hdr - } + NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment + if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) + { + // merkle prove txproof to the merkleroot in the corresponding hdr + } + } else retval = -22; } else retval = -1; } fprintf(stderr,"NSPV_gettransaction retval would have been %d\n",retval); From f508845b1af987c1418387e1d5a90ed2e18b58a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:35:32 -1100 Subject: [PATCH 284/659] -prints --- src/komodo_nSPV_fullnode.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index bae0870ce..d54cec36e 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -264,11 +264,11 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 ptr->common.nextht = nextht; ptr->common.numhdrs = (nextht - prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); - fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); + //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); for (i=0; icommon.numhdrs; i++) { hashBlock = NSPV_hdrhash(&ptr->common.hdrs[i]); - fprintf(stderr,"hdr[%d] %s\n",prevht+i,hashBlock.GetHex().c_str()); + //fprintf(stderr,"hdr[%d] %s\n",prevht+i,hashBlock.GetHex().c_str()); if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) { fprintf(stderr,"error setting hdr.%d\n",prevht+i); @@ -281,7 +281,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid); ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid); - fprintf(stderr,"ptr->prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); + //fprintf(stderr,"ptr->prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevtxlen + ptr->nexttxlen); } From 23b5c8f4289e8067ffae6be08b573a3f4ad29d41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:41:17 -1100 Subject: [PATCH 285/659] Bracket --- src/komodo_nSPV_wallet.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 8559293c4..ba2f66464 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -35,7 +35,6 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) // return(-5); //else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) // return(-6); - fprintf(stderr,"numhdrs.%d\n",ptr->common.numhdrs); for (i=ptr->common.numhdrs-1; i>0; i--) { blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); @@ -66,6 +65,13 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) else { NSPV_notarizations(height); // gets the prev and next notarizations + if ( NSPV_ntzsresult.prevntz.height == 0 ) + { + fprintf(stderr,"issue manual bracket\n"); + NSPV_notarizations(height-1); + NSPV_notarizations(height+1); + NSPV_notarizations(height); // gets the prev and next notarizations + } if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) { fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); From 49ec4ca2a356f9749d3ea009c7af3983395b345c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Jul 2019 23:43:36 -1100 Subject: [PATCH 286/659] Fix --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index ba2f66464..d5702f816 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -65,7 +65,7 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) else { NSPV_notarizations(height); // gets the prev and next notarizations - if ( NSPV_ntzsresult.prevntz.height == 0 ) + if ( NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height ) { fprintf(stderr,"issue manual bracket\n"); NSPV_notarizations(height-1); From 253223e58e224600bc7a3ef1aa3e6eb669600915 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 00:07:16 -1100 Subject: [PATCH 287/659] Calc merkle proofroot --- src/komodo_nSPV_wallet.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index d5702f816..6bd669a48 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -56,11 +56,11 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) { - int32_t retval = 0; + int32_t offset,retval = 0; NSPV_txproof(txid,height); if ( NSPV_txproofresult.txid != txid ) return(-1); - if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 ) + if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) retval = -20; else { @@ -75,12 +75,22 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) { fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); - if ( NSPV_ntzsresult.prevntz.height <= height && height <= NSPV_ntzsresult.nextntz.height ) + offset = (height - NSPV_ntzsresult.prevntz.height); + if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { - NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment + NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { - // merkle prove txproof to the merkleroot in the corresponding hdr + std::vector txids; std::vector proof; + proof.resize(NSPV_txproofresult.txlen); + memcpy(&proof[0],NSPV_txproofresult.tx,NSPV_txproofresult.txlen); + txids.push_back(txid); + proofroot = BitcoinGetProofMerkleRoot(proof,txids); + if ( proofroot != NSPV_ntzsproofresult.common[offset].hashMerkleRoot ) + { + fprintf(stderr,"proofroot.%s vs %s\n",proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common[offset].hashMerkleRoot.GetHex().c_str()); + return(-23); + } } } else retval = -22; } else retval = -1; From 129039d685caba2974b7ad6906eda09ffa6f4549 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 00:08:40 -1100 Subject: [PATCH 288/659] Syntax --- src/komodo_nSPV_wallet.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 6bd669a48..c54bfd894 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -81,14 +81,14 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { - std::vector txids; std::vector proof; + std::vector txids; std::vector proof; uint256 proofroot; proof.resize(NSPV_txproofresult.txlen); memcpy(&proof[0],NSPV_txproofresult.tx,NSPV_txproofresult.txlen); txids.push_back(txid); proofroot = BitcoinGetProofMerkleRoot(proof,txids); - if ( proofroot != NSPV_ntzsproofresult.common[offset].hashMerkleRoot ) + if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) { - fprintf(stderr,"proofroot.%s vs %s\n",proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common[offset].hashMerkleRoot.GetHex().c_str()); + fprintf(stderr,"proofroot.%s vs %s\n",proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); return(-23); } } From 2498cdfc88e827be9dd8dbc18595ac1e3636bcb0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 00:14:11 -1100 Subject: [PATCH 289/659] Fix --- src/komodo_nSPV_wallet.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index c54bfd894..346c1d678 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -82,14 +82,13 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { std::vector txids; std::vector proof; uint256 proofroot; - proof.resize(NSPV_txproofresult.txlen); - memcpy(&proof[0],NSPV_txproofresult.tx,NSPV_txproofresult.txlen); - txids.push_back(txid); + proof.resize(NSPV_txproofresult.txprooflen); + memcpy(&proof[0],NSPV_txproofresult.tx,NSPV_txproofresult.txprooflen); proofroot = BitcoinGetProofMerkleRoot(proof,txids); if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) { - fprintf(stderr,"proofroot.%s vs %s\n",proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); - return(-23); + fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",NSPV_txproofresult.txprooflen,proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); + retval = -23; } } } else retval = -22; From 01fe40136f000fafd712575504be7c09e4ed48c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 00:37:07 -1100 Subject: [PATCH 290/659] Initial notarisation validation --- src/komodo_nSPV.h | 20 ++++++++++++++++++-- src/komodo_nSPV_wallet.h | 20 ++++++++++---------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9d00d0ba6..87d8cb865 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -421,8 +421,24 @@ uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std: return(desttxid); } -int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *txidp,int32_t *txidhtp,uint256 *desttxidp,CTransaction tx) +int32_t NSPV_pubkeysextract(uint8_t pubkeys[64][33],CTransaction tx,uint8_t elected[64][33]) { - return(0); + int32_t numsigs = 0; + return(numsigs); +} + +int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *txidp,uint256 *desttxidp,CTransaction tx,int32_t ntzheight) +{ + int32_t numsigs; uint8_t elected[64][33],sigkeys[64][33]; char *symbol; std::vector opret; + if ( tx.vout.size() >= 2 ) + { + symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; + komodo_notaries(pubkeys,ntzheight,0); + numsigs = NSPV_pubkeysextract(sigkeys,tx,elected); + GetOpReturnData(tx.vout[1].scriptPubKey,opret); + *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret); + *txidp = tx.GetHash(); + return(0); + } else return(-1); } #endif // KOMODO_NSPV_H diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 346c1d678..4809aae81 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -29,12 +29,12 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-2); else if ( tx.GetHash() != ptr->nexttxid ) return(-3); - else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid,tx) < 0 ) + else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&desttxid,tx,ptr->common.nextht) < 0 ) return(-4); - //else if ( height != ptr->common.nextht ) - // return(-5); - //else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[ptr->common.numhdrs-1],sizeof(*ptr->common.hdrs)) != blockhash ) - // return(-6); + else if ( height != ptr->common.nextht ) + return(-5); + else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) + return(-6); for (i=ptr->common.numhdrs-1; i>0; i--) { blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); @@ -45,12 +45,12 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-6); else if ( tx.GetHash() != ptr->prevtxid ) return(-7); - else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&txidht,&desttxid,tx) < 0 ) + else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&desttxid,tx,ptr->common.prevht) < 0 ) return(-8); - //else if ( height != ptr->common.prevht ) - // return(-9); - //else if ( NSPV_doublesha256((uint8_t *)&ptr->common.hdrs[0],sizeof(*ptr->common.hdrs)) != blockhash ) - // return(-10); + else if ( height != ptr->common.prevht ) + return(-9); + else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) + return(-10); return(0); } From 5a3e0afd42fa767114b83a0051787fd1fe6b4ad3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 00:38:21 -1100 Subject: [PATCH 291/659] Syntax --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 87d8cb865..74a1b3866 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -433,7 +433,7 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t if ( tx.vout.size() >= 2 ) { symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - komodo_notaries(pubkeys,ntzheight,0); + komodo_notaries(elected,ntzheight,0); numsigs = NSPV_pubkeysextract(sigkeys,tx,elected); GetOpReturnData(tx.vout[1].scriptPubKey,opret); *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret); From 2869910d2b6f0cf3fcf9ff93c362663f060665b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 00:42:51 -1100 Subject: [PATCH 292/659] +print --- src/komodo_nSPV_wallet.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 4809aae81..73a3acdca 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -34,23 +34,26 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) else if ( height != ptr->common.nextht ) return(-5); else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) + { + fprintf(stderr,"hdr.%s vs blockhash.%s\n",NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1].GetHex().c_str(),blockhash.GetHex().c_str())); return(-6); + } for (i=ptr->common.numhdrs-1; i>0; i--) { blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) - return(-i-11); + return(-i-12); } if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) - return(-6); - else if ( tx.GetHash() != ptr->prevtxid ) return(-7); - else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&desttxid,tx,ptr->common.prevht) < 0 ) + else if ( tx.GetHash() != ptr->prevtxid ) return(-8); - else if ( height != ptr->common.prevht ) + else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&desttxid,tx,ptr->common.prevht) < 0 ) return(-9); - else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) + else if ( height != ptr->common.prevht ) return(-10); + else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) + return(-11); return(0); } From cb388ff8b1573129f97e12a1596a08fea129d1c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 00:45:38 -1100 Subject: [PATCH 293/659] Test --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 73a3acdca..5b8710c56 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -35,7 +35,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-5); else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) { - fprintf(stderr,"hdr.%s vs blockhash.%s\n",NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1].GetHex().c_str(),blockhash.GetHex().c_str())); + fprintf(stderr,"hdr.%s vs blockhash.%s\n",NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]).GetHex().c_str(),blockhash.GetHex().c_str())); return(-6); } for (i=ptr->common.numhdrs-1; i>0; i--) From 8c0f0c8ebf0e0fda0b23652903ac37f4f1407430 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 00:52:17 -1100 Subject: [PATCH 294/659] -) --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 5b8710c56..4a864c3c2 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -35,7 +35,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-5); else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) { - fprintf(stderr,"hdr.%s vs blockhash.%s\n",NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]).GetHex().c_str(),blockhash.GetHex().c_str())); + fprintf(stderr,"hdr.%s vs blockhash.%s\n",NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]).GetHex().c_str(),blockhash.GetHex().c_str()); return(-6); } for (i=ptr->common.numhdrs-1; i>0; i--) From b6b6e45f0233001329690e0bb85f8a28b885c6b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 00:58:08 -1100 Subject: [PATCH 295/659] +print --- src/komodo_nSPV.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 74a1b3866..3b1182440 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -436,7 +436,9 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t komodo_notaries(elected,ntzheight,0); numsigs = NSPV_pubkeysextract(sigkeys,tx,elected); GetOpReturnData(tx.vout[1].scriptPubKey,opret); - *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret); + if ( opret.size() >= 32*2+4*2 ) + *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,&opret[4]); + fprintf(stderr,"ntzht.%d %s txid.%s\n",*heightp,*blockhashp.GetHex().c_str(),*desttxidp.GetHex().c_str()); *txidp = tx.GetHash(); return(0); } else return(-1); From e1f53fb668fca90a20e6d22a7314b8f547c90274 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:00:38 -1100 Subject: [PATCH 296/659] Offset --- src/komodo_nSPV.h | 10 +++++----- src/komodo_nSPV_fullnode.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3b1182440..c339e78df 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -410,14 +410,14 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) else return(-1); } -uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret) +uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret,int32_t offset) { uint256 desttxid; int32_t i; - iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); + iguana_rwnum(0,&opret[32+offset],sizeof(*heightp),heightp); for (i=0; i<32; i++) - ((uint8_t *)blockhashp)[i] = opret[4 + i]; + ((uint8_t *)blockhashp)[i] = opret[4 + i + offset]; for (i=0; i<32; i++) - ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; + ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i + offset]; return(desttxid); } @@ -437,7 +437,7 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t numsigs = NSPV_pubkeysextract(sigkeys,tx,elected); GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4*2 ) - *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,&opret[4]); + *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret,4); fprintf(stderr,"ntzht.%d %s txid.%s\n",*heightp,*blockhashp.GetHex().c_str(),*desttxidp.GetHex().c_str()); *txidp = tx.GetHash(); return(0); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index d54cec36e..cce334e8d 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -47,7 +47,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des return(-1); txids[0] = nota.first; txidhts[0] = txidht; - desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash,symbol,E_MARSHAL(ss << nota.second)); + desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash,symbol,E_MARSHAL(ss << nota.second),0); //if ( height != 2668 ) // fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); if ( ntzheights[0] == height-1 ) // offset the +1 from caller @@ -62,7 +62,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des { txids[1] = nota.first; txidhts[1] = txidht; - desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash,symbol,E_MARSHAL(ss << nota.second)); + desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash,symbol,E_MARSHAL(ss << nota.second),0); } return(0); } From 03fe4d6627efc6fdbb57fbbc3f74a04ddd8d017b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:01:57 -1100 Subject: [PATCH 297/659] () --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c339e78df..3aa661738 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -438,7 +438,7 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4*2 ) *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret,4); - fprintf(stderr,"ntzht.%d %s txid.%s\n",*heightp,*blockhashp.GetHex().c_str(),*desttxidp.GetHex().c_str()); + fprintf(stderr,"ntzht.%d %s txid.%s\n",*heightp,(*blockhashp).GetHex().c_str(),(*desttxidp).GetHex().c_str()); *txidp = tx.GetHash(); return(0); } else return(-1); From 2f4ff0b103aa24b726c24b63943968073dd46c7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:07:20 -1100 Subject: [PATCH 298/659] Print --- src/komodo_nSPV.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3aa661738..ab358f5d6 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -438,7 +438,12 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4*2 ) *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret,4); - fprintf(stderr,"ntzht.%d %s txid.%s\n",*heightp,(*blockhashp).GetHex().c_str(),(*desttxidp).GetHex().c_str()); + { + int z; + for (z=0; z<68; z++) + fprintf(stderr,"%02x",opret[z]); + } + fprintf(stderr," ntzht.%d %s txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(*desttxidp).GetHex().c_str(),(int32_t)opret.size()); *txidp = tx.GetHash(); return(0); } else return(-1); From 03ce22bf093a9c549cb6faf82f6449b8d689d0c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:15:14 -1100 Subject: [PATCH 299/659] Tweak --- src/komodo_nSPV.h | 35 +++++++++++++++++++++++------------ src/komodo_nSPV_fullnode.h | 4 ++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index ab358f5d6..d77f97d0c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -410,23 +410,34 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) else return(-1); } -uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret,int32_t offset) -{ - uint256 desttxid; int32_t i; - iguana_rwnum(0,&opret[32+offset],sizeof(*heightp),heightp); - for (i=0; i<32; i++) - ((uint8_t *)blockhashp)[i] = opret[4 + i + offset]; - for (i=0; i<32; i++) - ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i + offset]; - return(desttxid); -} - int32_t NSPV_pubkeysextract(uint8_t pubkeys[64][33],CTransaction tx,uint8_t elected[64][33]) { int32_t numsigs = 0; return(numsigs); } +uint256 NSPV_DBopretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret) +{ + uint256 desttxid; int32_t i; + iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); + for (i=0; i<32; i++) + ((uint8_t *)blockhashp)[i] = opret[i]; + for (i=0; i<32; i++) + ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; + return(desttxid); +} + +uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret) +{ + uint256 desttxid; int32_t i; + iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); + for (i=0; i<32; i++) + ((uint8_t *)blockhashp)[i] = opret[i]; + for (i=0; i<32; i++) + ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; + return(desttxid); +} + int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *txidp,uint256 *desttxidp,CTransaction tx,int32_t ntzheight) { int32_t numsigs; uint8_t elected[64][33],sigkeys[64][33]; char *symbol; std::vector opret; @@ -437,7 +448,7 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t numsigs = NSPV_pubkeysextract(sigkeys,tx,elected); GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4*2 ) - *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret,4); + *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret); { int z; for (z=0; z<68; z++) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index cce334e8d..01e07cb07 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -47,7 +47,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des return(-1); txids[0] = nota.first; txidhts[0] = txidht; - desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash,symbol,E_MARSHAL(ss << nota.second),0); + desttxids[0] = NSPV_DBopretextract(&ntzheights[0],&bhash,symbol,E_MARSHAL(ss << nota.second)); //if ( height != 2668 ) // fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); if ( ntzheights[0] == height-1 ) // offset the +1 from caller @@ -62,7 +62,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des { txids[1] = nota.first; txidhts[1] = txidht; - desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash,symbol,E_MARSHAL(ss << nota.second),0); + desttxids[1] = NSPV_DBopretextract(&ntzheights[1],&bhash,symbol,E_MARSHAL(ss << nota.second)); } return(0); } From 80e9cec7bc23e3c9880aef3ae07c365a1a367676 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:31:29 -1100 Subject: [PATCH 300/659] Tweak --- src/komodo_nSPV.h | 15 ++------------- src/komodo_nSPV_fullnode.h | 11 ++++++----- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d77f97d0c..f1f0cc82b 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -416,17 +416,6 @@ int32_t NSPV_pubkeysextract(uint8_t pubkeys[64][33],CTransaction tx,uint8_t elec return(numsigs); } -uint256 NSPV_DBopretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret) -{ - uint256 desttxid; int32_t i; - iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); - for (i=0; i<32; i++) - ((uint8_t *)blockhashp)[i] = opret[i]; - for (i=0; i<32; i++) - ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; - return(desttxid); -} - uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret) { uint256 desttxid; int32_t i; @@ -449,11 +438,11 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4*2 ) *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret); - { + /*{ int z; for (z=0; z<68; z++) fprintf(stderr,"%02x",opret[z]); - } + }*/ fprintf(stderr," ntzht.%d %s txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(*desttxidp).GetHex().c_str(),(int32_t)opret.size()); *txidp = tx.GetHash(); return(0); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 01e07cb07..579d02fa4 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -37,7 +37,7 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) { - int32_t txidht; Notarisation nota; char *symbol; uint256 bhash; + int32_t txidht; Notarisation nota; char *symbol; uint256 bhash0,bhash1; symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(txids,0,sizeof(*txids)*2); memset(desttxids,0,sizeof(*desttxids)*2); @@ -47,8 +47,8 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des return(-1); txids[0] = nota.first; txidhts[0] = txidht; - desttxids[0] = NSPV_DBopretextract(&ntzheights[0],&bhash,symbol,E_MARSHAL(ss << nota.second)); - //if ( height != 2668 ) + desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,E_MARSHAL(ss << nota.second)); + /*//if ( height != 2668 ) // fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); if ( ntzheights[0] == height-1 ) // offset the +1 from caller { @@ -57,13 +57,14 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des ntzheights[1] = ntzheights[0]; desttxids[1] = desttxids[0]; return(0); - } + }*/ if ( (txidht= ScanNotarisationsDB2(height,symbol,1440,nota)) != 0 ) { txids[1] = nota.first; txidhts[1] = txidht; - desttxids[1] = NSPV_DBopretextract(&ntzheights[1],&bhash,symbol,E_MARSHAL(ss << nota.second)); + desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,E_MARSHAL(ss << nota.second)); } + fprintf(stderr,"prev.(%s -> ht.%d %s) next.(%s -> ht.%d %s)\n",txids[0].GetHex().c_str(),ntzheights[0],bhash0.GetHex().c_str(),txids[1].GetHex().c_str(),ntzheights[1],bhash1.GetHex().c_str()); return(0); } From a043cef2fc6e83281dfb885ced54531aa7790353 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:43:03 -1100 Subject: [PATCH 301/659] Re-query ntz tx --- src/komodo_nSPV_fullnode.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 579d02fa4..2608ad3f5 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -37,7 +37,7 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) { - int32_t txidht; Notarisation nota; char *symbol; uint256 bhash0,bhash1; + int32_t txidht; CTransaction tx; Notarisation nota; char *symbol; std::vector opret; uint256 bhash0,bhash1,hashBlock; symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(txids,0,sizeof(*txids)*2); memset(desttxids,0,sizeof(*desttxids)*2); @@ -47,8 +47,14 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des return(-1); txids[0] = nota.first; txidhts[0] = txidht; - desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,E_MARSHAL(ss << nota.second)); - /*//if ( height != 2668 ) + if ( !GetTransaction(txids[0],tx,hashBlock,false) || tx.vout.size() < 2 ) + return(-2); + GetOpReturnData(tx.vout[1].scriptPubKey,opret); + if ( opret.size() >= 32*2+4*2 ) + desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,opret); + + /*desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,E_MARSHAL(ss << nota.second)); + //if ( height != 2668 ) // fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); if ( ntzheights[0] == height-1 ) // offset the +1 from caller { @@ -62,7 +68,12 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des { txids[1] = nota.first; txidhts[1] = txidht; - desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,E_MARSHAL(ss << nota.second)); + if ( !GetTransaction(txids[1],tx,hashBlock,false) || tx.vout.size() < 2 ) + return(-2); + GetOpReturnData(tx.vout[1].scriptPubKey,opret); + if ( opret.size() >= 32*2+4*2 ) + desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,opret); + //desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,E_MARSHAL(ss << nota.second)); } fprintf(stderr,"prev.(%s -> ht.%d %s) next.(%s -> ht.%d %s)\n",txids[0].GetHex().c_str(),ntzheights[0],bhash0.GetHex().c_str(),txids[1].GetHex().c_str(),ntzheights[1],bhash1.GetHex().c_str()); return(0); From 7cd2faf561401710a500227e17b24c9a1d9705d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:43:43 -1100 Subject: [PATCH 302/659] -print --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f1f0cc82b..27c015ea3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -443,7 +443,7 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t for (z=0; z<68; z++) fprintf(stderr,"%02x",opret[z]); }*/ - fprintf(stderr," ntzht.%d %s txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(*desttxidp).GetHex().c_str(),(int32_t)opret.size()); + //fprintf(stderr," ntzht.%d %s txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(*desttxidp).GetHex().c_str(),(int32_t)opret.size()); *txidp = tx.GetHash(); return(0); } else return(-1); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 2608ad3f5..615084aff 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -75,7 +75,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,opret); //desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,E_MARSHAL(ss << nota.second)); } - fprintf(stderr,"prev.(%s -> ht.%d %s) next.(%s -> ht.%d %s)\n",txids[0].GetHex().c_str(),ntzheights[0],bhash0.GetHex().c_str(),txids[1].GetHex().c_str(),ntzheights[1],bhash1.GetHex().c_str()); + //fprintf(stderr,"prev.(%s -> ht.%d %s) next.(%s -> ht.%d %s)\n",txids[0].GetHex().c_str(),ntzheights[0],bhash0.GetHex().c_str(),txids[1].GetHex().c_str(),ntzheights[1],bhash1.GetHex().c_str()); return(0); } From 27111cb1a38d491910409d08351c480a8c824a1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:50:13 -1100 Subject: [PATCH 303/659] Print --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 27c015ea3..4da0df07e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -443,8 +443,8 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t for (z=0; z<68; z++) fprintf(stderr,"%02x",opret[z]); }*/ - //fprintf(stderr," ntzht.%d %s txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(*desttxidp).GetHex().c_str(),(int32_t)opret.size()); *txidp = tx.GetHash(); + fprintf(stderr," ntzht.%d %s <- txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(*txidp).GetHex().c_str(),(int32_t)opret.size()); return(0); } else return(-1); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 615084aff..97d2824d3 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -50,7 +50,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des if ( !GetTransaction(txids[0],tx,hashBlock,false) || tx.vout.size() < 2 ) return(-2); GetOpReturnData(tx.vout[1].scriptPubKey,opret); - if ( opret.size() >= 32*2+4*2 ) + if ( opret.size() >= 32*2+4 ) desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,opret); /*desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,E_MARSHAL(ss << nota.second)); @@ -71,7 +71,7 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des if ( !GetTransaction(txids[1],tx,hashBlock,false) || tx.vout.size() < 2 ) return(-2); GetOpReturnData(tx.vout[1].scriptPubKey,opret); - if ( opret.size() >= 32*2+4*2 ) + if ( opret.size() >= 32*2+4 ) desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,opret); //desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,E_MARSHAL(ss << nota.second)); } From 24c33299169ccd9dd7c20116691d7a1c76f374d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:55:27 -1100 Subject: [PATCH 304/659] Test --- src/komodo_nSPV.h | 6 +++--- src/komodo_nSPV_fullnode.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4da0df07e..c7e5226d5 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -416,7 +416,7 @@ int32_t NSPV_pubkeysextract(uint8_t pubkeys[64][33],CTransaction tx,uint8_t elec return(numsigs); } -uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret) +uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std::vector opret,uint256 txid) { uint256 desttxid; int32_t i; iguana_rwnum(0,&opret[32],sizeof(*heightp),heightp); @@ -424,6 +424,7 @@ uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std: ((uint8_t *)blockhashp)[i] = opret[i]; for (i=0; i<32; i++) ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; + fprintf(stderr," ntzht.%d %s <- txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(txid).GetHex().c_str(),(int32_t)opret.size()); return(desttxid); } @@ -437,14 +438,13 @@ int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *t numsigs = NSPV_pubkeysextract(sigkeys,tx,elected); GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4*2 ) - *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret); + *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret,tx.GetHash()); /*{ int z; for (z=0; z<68; z++) fprintf(stderr,"%02x",opret[z]); }*/ *txidp = tx.GetHash(); - fprintf(stderr," ntzht.%d %s <- txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(*txidp).GetHex().c_str(),(int32_t)opret.size()); return(0); } else return(-1); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 97d2824d3..f8c753bee 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -50,8 +50,8 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des if ( !GetTransaction(txids[0],tx,hashBlock,false) || tx.vout.size() < 2 ) return(-2); GetOpReturnData(tx.vout[1].scriptPubKey,opret); - if ( opret.size() >= 32*2+4 ) - desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,opret); + //if ( opret.size() >= 32*2+4 ) + desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,opret,txids[0]); /*desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,E_MARSHAL(ss << nota.second)); //if ( height != 2668 ) @@ -71,8 +71,8 @@ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 des if ( !GetTransaction(txids[1],tx,hashBlock,false) || tx.vout.size() < 2 ) return(-2); GetOpReturnData(tx.vout[1].scriptPubKey,opret); - if ( opret.size() >= 32*2+4 ) - desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,opret); + //if ( opret.size() >= 32*2+4 ) + desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,opret,txids[1]); //desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,E_MARSHAL(ss << nota.second)); } //fprintf(stderr,"prev.(%s -> ht.%d %s) next.(%s -> ht.%d %s)\n",txids[0].GetHex().c_str(),ntzheights[0],bhash0.GetHex().c_str(),txids[1].GetHex().c_str(),ntzheights[1],bhash1.GetHex().c_str()); From 7143b2a0e3fb18a22003763a3d0fdb134893a689 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 01:57:47 -1100 Subject: [PATCH 305/659] Guard --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c7e5226d5..4dc6bc324 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -424,6 +424,7 @@ uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std: ((uint8_t *)blockhashp)[i] = opret[i]; for (i=0; i<32; i++) ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; + if ( *heightp != 2690 ) fprintf(stderr," ntzht.%d %s <- txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(txid).GetHex().c_str(),(int32_t)opret.size()); return(desttxid); } From 269c9120725fbd623b5ee7e61d6d227f4a20248e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 02:04:13 -1100 Subject: [PATCH 306/659] +print --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 97c0dc1c2..456ba6385 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -460,7 +460,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_NTZSRESP: NSPV_ntzsresp_purge(&NSPV_ntzsresult); NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); - fprintf(stderr,"got ntzs response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); + fprintf(stderr,"got ntzs response %u size.%d %s prev.%d, %s next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.height); break; case NSPV_NTZSPROOFRESP: NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); From 88617145c60cc97b9415705115411a76d10bf264 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 03:39:03 -1100 Subject: [PATCH 307/659] Change hdrsproof to taxied based, add unspentvalue to taproot --- src/cc/CCinclude.h | 2 +- src/cc/CCtx.cpp | 2 +- src/komodo_nSPV.h | 26 ++++++------ src/komodo_nSPV_fullnode.h | 81 +++++++++++++++++++++---------------- src/komodo_nSPV_superlite.h | 23 +++++++---- src/komodo_nSPV_wallet.h | 6 +-- src/wallet/rpcdump.cpp | 4 +- 7 files changed, 83 insertions(+), 61 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 85ff380ca..c4ef6c52c 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -174,7 +174,7 @@ static int32_t ignorevin; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); int32_t is_hexstr(char *str,int32_t n); bool myAddtomempool(CTransaction &tx, CValidationState *pstate = NULL, bool fSkipExpiry = false); -int32_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag); +int64_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag); bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout); bool mytxid_inmempool(uint256 txid); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index b51342be7..a3624fd67 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -365,7 +365,7 @@ int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCf return(0); } -int32_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag) +int64_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag) { CCoins coins; //fprintf(stderr,"CCgettxoud %s/v%d\n",txid.GetHex().c_str(),vout); diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4dc6bc324..c2fd7b40d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -240,7 +240,8 @@ void NSPV_inforesp_purge(struct NSPV_inforesp *ptr) struct NSPV_txproof { uint256 txid; - int32_t height; + int64_t unspentvalue; + int32_t height,vout; uint16_t txlen,txprooflen; uint8_t *tx,*txproof; }; @@ -249,7 +250,9 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p { int32_t len = 0; len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->unspentvalue),&ptr->unspentvalue); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); return(len); @@ -412,7 +415,7 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) int32_t NSPV_pubkeysextract(uint8_t pubkeys[64][33],CTransaction tx,uint8_t elected[64][33]) { - int32_t numsigs = 0; + int32_t numsigs = 13; return(numsigs); } @@ -429,24 +432,21 @@ uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std: return(desttxid); } -int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *txidp,uint256 *desttxidp,CTransaction tx,int32_t ntzheight) +int32_t NSPV_notarizationextract(int32_t *ntzheightp,uint256 *blockhashp,uint256 *desttxidp,CTransaction tx) { int32_t numsigs; uint8_t elected[64][33],sigkeys[64][33]; char *symbol; std::vector opret; if ( tx.vout.size() >= 2 ) { symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - komodo_notaries(elected,ntzheight,0); - numsigs = NSPV_pubkeysextract(sigkeys,tx,elected); GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4*2 ) - *desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret,tx.GetHash()); - /*{ - int z; - for (z=0; z<68; z++) - fprintf(stderr,"%02x",opret[z]); - }*/ - *txidp = tx.GetHash(); - return(0); + { + *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); + komodo_notaries(elected,*ntzheightp,0); + if ( (numsigs= NSPV_pubkeysextract(sigkeys,tx,elected)) < 12 ) + return(-3); + return(0); + } else return(-2); } else return(-1); } #endif // KOMODO_NSPV_H diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index f8c753bee..b958e877d 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -21,7 +21,7 @@ #include "notarisationdb.h" -uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) +/*uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) { uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(&txid,0,sizeof(txid)); @@ -33,7 +33,7 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) txid = nota.first; } return(txid); -} +}*/ int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) { @@ -206,12 +206,13 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int return(sizeof(*ptr)); } -int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) +int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32_t height) { int32_t flag = 0,len = 0; uint256 hashBlock; CBlock block; CBlockIndex *pindex; if ( (ptr->tx= NSPV_getrawtx(hashBlock,&ptr->txlen,txid)) == 0 ) return(-1); ptr->txid = txid; + ptr->vout = vout; ptr->height = height; if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) { @@ -237,6 +238,8 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height) ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); memcpy(ptr->txproof,&proof[0],ptr->txprooflen); } + //int64_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag); + ptr->unspentvalue = CCgettxout(txid,vout,1,1); //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); } @@ -264,22 +267,40 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) return(-1); } -int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht) +int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid,uint256 nextntxtxid) { - int32_t i; uint256 hashBlock; - if ( prevht > nextht || (nextht-prevht) > 1440 ) + int32_t i; uint256 hashBlock,bhash0,bhash1,desttxid0,desttxid1; CTransaction tx; + ptr->prevtxid = prevntztxid; + ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid); + ptr->prevtxidht = komodo_blockheight(hashBlock); + if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) + return(-1); + else if ( NSPV_notarizationextract(&ptr->common.prevht,&bhash0,&desttxid0,tx) < 0 ) + return(-2); + else if ( komodo_blockheight(bhash0) != ptr->common.prevht ) + return(-3); + + ptr->nexttxid = nextntztxid; + ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid); + ptr->nexttxidht = komodo_blockheight(hashBlock); + if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) + return(-4); + else if ( NSPV_notarizationextract(&ptr->common.nextht,&bhash1,&desttxid1,tx) < 0 ) + return(-5); + else if ( komodo_blockheight(bhash1) != ptr->common.nextht ) + return(-6); + + else if ( ptr->common.prevht > ptr->common.nextht || (ptr->common.nextht - ptr->common.prevht) > 1440 ) { fprintf(stderr,"illegal prevht.%d nextht.%d\n",prevht,nextht); - return(-1); + return(-7); } - ptr->common.prevht = prevht; - ptr->common.nextht = nextht; ptr->common.numhdrs = (nextht - prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); for (i=0; icommon.numhdrs; i++) { - hashBlock = NSPV_hdrhash(&ptr->common.hdrs[i]); + //hashBlock = NSPV_hdrhash(&ptr->common.hdrs[i]); //fprintf(stderr,"hdr[%d] %s\n",prevht+i,hashBlock.GetHex().c_str()); if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) { @@ -289,11 +310,6 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3 return(-1); } } - ptr->prevtxid = NSPV_getnotarization_txid(&ptr->prevtxidht,prevht); - ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid); - ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht); - ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid); - //fprintf(stderr,"ptr->prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevtxlen + ptr->nexttxlen); } @@ -306,7 +322,7 @@ int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) len = (int32_t)(sizeof(*ptr) - sizeof(ptr->spent.tx) - sizeof(ptr->spent.txproof)); if ( CCgetspenttxid(ptr->spent.txid,ptr->spentvini,ptr->spent.height,txid,vout) == 0 ) { - if ( NSPV_gettxproof(&ptr->spent,ptr->spent.txid,ptr->spent.height) > 0 ) + if ( NSPV_gettxproof(&ptr->spent,0,ptr->spent.txid,ptr->spent.height) > 0 ) len += ptr->spent.txlen + ptr->spent.txprooflen; else { @@ -398,26 +414,22 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { if ( timestamp > pfrom->prevtimes[ind] ) { - struct NSPV_ntzsproofresp P; int32_t prevht,nextht; + struct NSPV_ntzsproofresp P; uint256 prevntz,nextntz; if ( len == 1+sizeof(prevht)+sizeof(nextht) ) { - iguana_rwnum(0,&request[1],sizeof(prevht),&prevht); - iguana_rwnum(0,&request[1+sizeof(prevht)],sizeof(nextht),&nextht); - if ( prevht != 0 && nextht != 0 && nextht >= prevht ) + iguana_rwbignum(0,&request[1],sizeof(prevntz),(uint8_t *)&prevntz); + iguana_rwbignum(0,&request[1+sizeof(prevntz)],sizeof(nextntz),(uint8_t *)&nextntz); + memset(&P,0,sizeof(P)); + if ( (slen= NSPV_getntzsproofresp(&P,prevntz,nextntz)) > 0 ) { - memset(&P,0,sizeof(P)); - if ( (slen= NSPV_getntzsproofresp(&P,prevht,nextht)) > 0 ) + response.resize(1 + slen); + response[0] = NSPV_NTZSPROOFRESP; + if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) { - response.resize(1 + slen); - response[0] = NSPV_NTZSPROOFRESP; - P.common.numhdrs = (nextht - prevht + 1); - if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) - { - pfrom->PushMessage("nSPV",response); - pfrom->prevtimes[ind] = timestamp; - } - NSPV_ntzsproofresp_purge(&P); + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; } + NSPV_ntzsproofresp_purge(&P); } } } @@ -426,14 +438,15 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { if ( timestamp > pfrom->prevtimes[ind] ) { - struct NSPV_txproof P; uint256 txid; int32_t height; + struct NSPV_txproof P; uint256 txid; int32_t height,vout; if ( len == 1+sizeof(txid)+sizeof(height) ) { iguana_rwnum(0,&request[1],sizeof(height),&height); - iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); + iguana_rwnum(0,&request[1+sizeof(height)],sizeof(vout),&vout); + iguana_rwbignum(0,&request[1+sizeof(height)+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); //fprintf(stderr,"got txid ht.%d\n",txid.GetHex().c_str(),height); memset(&P,0,sizeof(P)); - if ( (slen= NSPV_gettxproof(&P,txid,height)) > 0 ) + if ( (slen= NSPV_gettxproof(&P,vout,txid,height)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_TXPROOFRESP; diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 456ba6385..bda60e1ea 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -344,20 +344,18 @@ UniValue NSPV_notarizations(int32_t height) return(NSPV_ntzs_json(&N)); } -UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) +UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) { uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsproofresp H; - if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight ) - return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); msg[len++] = NSPV_NTZSPROOF; - len += iguana_rwnum(1,&msg[len],sizeof(prevheight),&prevheight); - len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight); + len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); + len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i= nextheight ) + if ( NSPV_ntzsproofresult.prevtxid == prevtxid && NSPV_ntzsproofresult.nexttxid == nexttxid ) return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); } } @@ -365,13 +363,24 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight) return(NSPV_ntzsproof_json(&H)); } -UniValue NSPV_txproof(uint256 txid,int32_t height) +UniValue NSPV_hdrsproof(int32_t prevht,int32_t nextht) +{ + uint256 prevtxid,nexttxid; + NSPV_notarizations(prevht); + prevtxid = NSPV_ntzsresult.prevntz.txid; + NSPV_notarizations(nextht); + nexttxid = NSPV_ntzsresult.nextntz.txid; + return(NSPV_txidhdrsproof(prevtxid,nexttxid)); +} + +UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) { uint8_t msg[64]; int32_t i,len = 0; struct NSPV_txproof P; if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) return(NSPV_txproof_json(&NSPV_txproofresult)); msg[len++] = NSPV_TXPROOF; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); + len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); //fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 4a864c3c2..1cfad0d29 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -29,7 +29,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-2); else if ( tx.GetHash() != ptr->nexttxid ) return(-3); - else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&desttxid,tx,ptr->common.nextht) < 0 ) + else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 ) return(-4); else if ( height != ptr->common.nextht ) return(-5); @@ -48,7 +48,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-7); else if ( tx.GetHash() != ptr->prevtxid ) return(-8); - else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&desttxid,tx,ptr->common.prevht) < 0 ) + else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 ) return(-9); else if ( height != ptr->common.prevht ) return(-10); @@ -81,7 +81,7 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { - NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); + NSPV_hdrsproof(NSPV_ntzsresult.prevtxid,NSPV_ntzsresult.nexttxid); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { std::vector txids; std::vector proof; uint256 proofroot; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index d5bc66209..a99d6f071 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -981,7 +981,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); UniValue NSPV_notarizations(int32_t height); UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight); -UniValue NSPV_txproof(uint256 txid,int32_t vout); +UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t vout); uint256 Parseuint256(const char *hexstr); extern std::string NSPV_address; @@ -1057,7 +1057,7 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp) throw runtime_error("nspv_txproof txid height\n"); txid = Parseuint256((char *)params[0].get_str().c_str()); height = atoi((char *)params[1].get_str().c_str()); - return(NSPV_txproof(txid,height)); + return(NSPV_txproof(0,txid,height)); } UniValue nspv_spend(const UniValue& params, bool fHelp) From db1c0bb740eb87054b7bf3b64a87bf3ba28a6796 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 03:46:56 -1100 Subject: [PATCH 308/659] Syntax --- src/komodo_nSPV_fullnode.h | 10 +++++----- src/komodo_nSPV_wallet.h | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index b958e877d..e2bc60acc 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -267,7 +267,7 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) return(-1); } -int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid,uint256 nextntxtxid) +int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid,uint256 nextntztxid) { int32_t i; uint256 hashBlock,bhash0,bhash1,desttxid0,desttxid1; CTransaction tx; ptr->prevtxid = prevntztxid; @@ -292,19 +292,19 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid else if ( ptr->common.prevht > ptr->common.nextht || (ptr->common.nextht - ptr->common.prevht) > 1440 ) { - fprintf(stderr,"illegal prevht.%d nextht.%d\n",prevht,nextht); + fprintf(stderr,"illegal prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); return(-7); } - ptr->common.numhdrs = (nextht - prevht + 1); + ptr->common.numhdrs = (ptr->common.nextht - ptr->common.prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); for (i=0; icommon.numhdrs; i++) { //hashBlock = NSPV_hdrhash(&ptr->common.hdrs[i]); //fprintf(stderr,"hdr[%d] %s\n",prevht+i,hashBlock.GetHex().c_str()); - if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 ) + if ( NSPV_setequihdr(&ptr->common.hdrs[i],ptr->common.prevht+i) < 0 ) { - fprintf(stderr,"error setting hdr.%d\n",prevht+i); + fprintf(stderr,"error setting hdr.%d\n",ptr->common.prevht+i); free(ptr->common.hdrs); ptr->common.hdrs = 0; return(-1); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 1cfad0d29..615eff2ad 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -57,10 +57,10 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(0); } -int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) +int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransaction &tx) { int32_t offset,retval = 0; - NSPV_txproof(txid,height); + NSPV_txproof(vout,txid,height); if ( NSPV_txproofresult.txid != txid ) return(-1); if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) @@ -243,9 +243,9 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st mtx.vout.push_back(CTxOut(0,opret)); for (i=0; i Date: Sun, 7 Jul 2019 03:49:44 -1100 Subject: [PATCH 309/659] Syntax --- src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index e2bc60acc..ba73a2127 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -415,7 +415,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_ntzsproofresp P; uint256 prevntz,nextntz; - if ( len == 1+sizeof(prevht)+sizeof(nextht) ) + if ( len == 1+sizeof(prevntz)+sizeof(nextntz) ) { iguana_rwbignum(0,&request[1],sizeof(prevntz),(uint8_t *)&prevntz); iguana_rwbignum(0,&request[1+sizeof(prevntz)],sizeof(nextntz),(uint8_t *)&nextntz); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 615eff2ad..35221b65b 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -81,7 +81,7 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { - NSPV_hdrsproof(NSPV_ntzsresult.prevtxid,NSPV_ntzsresult.nexttxid); + NSPV_hdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { std::vector txids; std::vector proof; uint256 proofroot; From 2181bcd9c43cafee10354a1fc88b65c6fd818ce3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 03:51:01 -1100 Subject: [PATCH 310/659] Syntax --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 35221b65b..2ebabaa0c 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -35,7 +35,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-5); else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) { - fprintf(stderr,"hdr.%s vs blockhash.%s\n",NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]).GetHex().c_str(),blockhash.GetHex().c_str()); + //fprintf(stderr,"hdr.%s vs blockhash.%s\n",NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]).GetHex().c_str(),blockhash.GetHex().c_str()); return(-6); } for (i=ptr->common.numhdrs-1; i>0; i--) @@ -81,7 +81,7 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { - NSPV_hdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); + NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { std::vector txids; std::vector proof; uint256 proofroot; From 38a622681125266eb103af54c0d1f6316defbd8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 03:54:26 -1100 Subject: [PATCH 311/659] Syntax --- src/wallet/rpcdump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index a99d6f071..e13276960 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -981,7 +981,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); UniValue NSPV_notarizations(int32_t height); UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight); -UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t vout); +UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height); uint256 Parseuint256(const char *hexstr); extern std::string NSPV_address; From 899e223796c7b8f68da9fde34c36eec4ca6dc4f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 04:05:17 -1100 Subject: [PATCH 312/659] Test --- src/komodo_nSPV_superlite.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index bda60e1ea..e3dad5752 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -376,13 +376,13 @@ UniValue NSPV_hdrsproof(int32_t prevht,int32_t nextht) UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) { uint8_t msg[64]; int32_t i,len = 0; struct NSPV_txproof P; - if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) - return(NSPV_txproof_json(&NSPV_txproofresult)); + //if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) + // return(NSPV_txproof_json(&NSPV_txproofresult)); msg[len++] = NSPV_TXPROOF; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); - //fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height); + fprintf(stderr,"req txproof %s/v%d at height.%d\n",txid.GetHex().c_str(),vout,height); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i Date: Sun, 7 Jul 2019 04:07:27 -1100 Subject: [PATCH 313/659] Fix error check --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index ba73a2127..c4b13f173 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -439,7 +439,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_txproof P; uint256 txid; int32_t height,vout; - if ( len == 1+sizeof(txid)+sizeof(height) ) + if ( len == 1+sizeof(txid)+sizeof(height)+sizeof(vout) ) { iguana_rwnum(0,&request[1],sizeof(height),&height); iguana_rwnum(0,&request[1+sizeof(height)],sizeof(vout),&vout); From 011a4f90aeafcc8ec500c7b74162df7d61347be4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 04:11:52 -1100 Subject: [PATCH 314/659] Prints --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index c4b13f173..746ca83d5 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -444,7 +444,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwnum(0,&request[1],sizeof(height),&height); iguana_rwnum(0,&request[1+sizeof(height)],sizeof(vout),&vout); iguana_rwbignum(0,&request[1+sizeof(height)+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); - //fprintf(stderr,"got txid ht.%d\n",txid.GetHex().c_str(),height); + fprintf(stderr,"got txid %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); memset(&P,0,sizeof(P)); if ( (slen= NSPV_gettxproof(&P,vout,txid,height)) > 0 ) { From 6274db79a66812c052720e5b001b92545dfc54ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 04:17:57 -1100 Subject: [PATCH 315/659] Test --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_fullnode.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c2fd7b40d..1655fcf9a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -255,6 +255,7 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); + fprintf(stderr,"rwtxproof len.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 746ca83d5..9092cbc30 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -450,6 +450,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_TXPROOFRESP; + fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) { pfrom->PushMessage("nSPV",response); From 63732deda7b979f92488908f50d4240ce1f39317 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 04:23:08 -1100 Subject: [PATCH 316/659] Struct padding --- src/komodo_nSPV.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1655fcf9a..61cedc77d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -241,7 +241,7 @@ struct NSPV_txproof { uint256 txid; int64_t unspentvalue; - int32_t height,vout; + int32_t height,vout,pad; uint16_t txlen,txprooflen; uint8_t *tx,*txproof; }; @@ -253,6 +253,7 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->unspentvalue),&ptr->unspentvalue); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad),&ptr->pad); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); fprintf(stderr,"rwtxproof len.%d\n",len); From 786da24f91d2d464c2920f16ec905b566a105bbc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 04:28:56 -1100 Subject: [PATCH 317/659] +print --- src/komodo_nSPV.h | 5 ++++- src/komodo_nSPV_fullnode.h | 1 - src/komodo_nSPV_wallet.h | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 61cedc77d..d44a7ddae 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -256,7 +256,6 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad),&ptr->pad); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); - fprintf(stderr,"rwtxproof len.%d\n",len); return(len); } @@ -408,10 +407,14 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) { std::vector rawdata; + fprintf(stderr,"extract %d bytes\n",datalen); rawdata.resize(datalen); memcpy(&rawdata[0],data,datalen); if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) + { + fprintf(stderr,"extracted %s\n",tx.GetHex().c_str()); return(0); + } else return(-1); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 9092cbc30..746ca83d5 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -450,7 +450,6 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_TXPROOFRESP; - fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) { pfrom->PushMessage("nSPV",response); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 2ebabaa0c..899a2707b 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -63,7 +63,7 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio NSPV_txproof(vout,txid,height); if ( NSPV_txproofresult.txid != txid ) return(-1); - if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) + else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) retval = -20; else { From d6028580a3b48af7ebf920d21c010da2abc9ed3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 04:43:05 -1100 Subject: [PATCH 318/659] +print --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_fullnode.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d44a7ddae..3b79ff2e7 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -286,6 +286,7 @@ int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nextht),&ptr->nextht); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); + fprintf(stderr,"rwcommon prev.%d next.%d\n",ptr->prevht,ptr->nextht); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 746ca83d5..4981219f8 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -295,6 +295,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid fprintf(stderr,"illegal prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); return(-7); } + fprintf(stderr,"prevht.%d nexht.%d\n",ptr->common.prevht,ptr->common.nextht); ptr->common.numhdrs = (ptr->common.nextht - ptr->common.prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); From 4fd0f12e72c5b7c78e024eca09f4b0b1b796ef0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 04:44:31 -1100 Subject: [PATCH 319/659] +print --- src/komodo_nSPV_fullnode.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 4981219f8..d09f3375f 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -421,6 +421,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwbignum(0,&request[1],sizeof(prevntz),(uint8_t *)&prevntz); iguana_rwbignum(0,&request[1+sizeof(prevntz)],sizeof(nextntz),(uint8_t *)&nextntz); memset(&P,0,sizeof(P)); + fprintf(stderr,"msg prev.%s next.%s\n",prevntz.GetHex().c_str(),nextntz.GetHex().c_str()); if ( (slen= NSPV_getntzsproofresp(&P,prevntz,nextntz)) > 0 ) { response.resize(1 + slen); From 98ae008b1acfa9fd3eb50210f8a308c1c101e9f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 04:47:09 -1100 Subject: [PATCH 320/659] Test --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3b79ff2e7..14dc314b3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -413,7 +413,7 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) memcpy(&rawdata[0],data,datalen); if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) { - fprintf(stderr,"extracted %s\n",tx.GetHex().c_str()); + fprintf(stderr,"extracted %s\n",tx.GetHash().GetHex().c_str()); return(0); } else return(-1); From b37111a2b0a206b8d994f0e2099f78a804a87cc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 04:57:37 -1100 Subject: [PATCH 321/659] Tweak --- src/komodo_nSPV.h | 1 - src/komodo_nSPV_fullnode.h | 22 +++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 14dc314b3..5e05b4627 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -408,7 +408,6 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) { std::vector rawdata; - fprintf(stderr,"extract %d bytes\n",datalen); rawdata.resize(datalen); memcpy(&rawdata[0],data,datalen); if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index d09f3375f..210c721b9 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -169,9 +169,9 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check return(0); } -uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid) +uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,uint16_t *txlenp,uint256 txid) { - CTransaction tx; uint8_t *rawtx = 0; + uint8_t *rawtx = 0; *txlenp = 0; { LOCK(cs_main); @@ -208,8 +208,8 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32_t height) { - int32_t flag = 0,len = 0; uint256 hashBlock; CBlock block; CBlockIndex *pindex; - if ( (ptr->tx= NSPV_getrawtx(hashBlock,&ptr->txlen,txid)) == 0 ) + int32_t flag = 0,len = 0; CTransaction _tx; uint256 hashBlock; CBlock block; CBlockIndex *pindex; + if ( (ptr->tx= NSPV_getrawtx(_tx,hashBlock,&ptr->txlen,txid)) == 0 ) return(-1); ptr->txid = txid; ptr->vout = vout; @@ -271,21 +271,17 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid { int32_t i; uint256 hashBlock,bhash0,bhash1,desttxid0,desttxid1; CTransaction tx; ptr->prevtxid = prevntztxid; - ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid); + ptr->prevntz = NSPV_getrawtx(tx,hashBlock,&ptr->prevtxlen,ptr->prevtxid); ptr->prevtxidht = komodo_blockheight(hashBlock); - if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) - return(-1); - else if ( NSPV_notarizationextract(&ptr->common.prevht,&bhash0,&desttxid0,tx) < 0 ) + if ( NSPV_notarizationextract(&ptr->common.prevht,&bhash0,&desttxid0,tx) < 0 ) return(-2); else if ( komodo_blockheight(bhash0) != ptr->common.prevht ) return(-3); ptr->nexttxid = nextntztxid; - ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid); + ptr->nextntz = NSPV_getrawtx(tx,hashBlock,&ptr->nexttxlen,ptr->nexttxid); ptr->nexttxidht = komodo_blockheight(hashBlock); - if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) - return(-4); - else if ( NSPV_notarizationextract(&ptr->common.nextht,&bhash1,&desttxid1,tx) < 0 ) + if ( NSPV_notarizationextract(&ptr->common.nextht,&bhash1,&desttxid1,tx) < 0 ) return(-5); else if ( komodo_blockheight(bhash1) != ptr->common.nextht ) return(-6); @@ -295,7 +291,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid fprintf(stderr,"illegal prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); return(-7); } - fprintf(stderr,"prevht.%d nexht.%d\n",ptr->common.prevht,ptr->common.nextht); + fprintf(stderr,"%s -> prevht.%d, %s -> nexht.%d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); ptr->common.numhdrs = (ptr->common.nextht - ptr->common.prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); From 1eefc92892dba0e2115a1b1b6dd0fa412af4327d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 05:08:49 -1100 Subject: [PATCH 322/659] +print --- src/komodo_nSPV.h | 6 +++--- src/komodo_nSPV_fullnode.h | 8 ++++---- src/komodo_nSPV_wallet.h | 5 +---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 5e05b4627..d8f9745e4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -412,7 +412,7 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) memcpy(&rawdata[0],data,datalen); if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) { - fprintf(stderr,"extracted %s\n",tx.GetHash().GetHex().c_str()); + //fprintf(stderr,"extracted %s\n",tx.GetHash().GetHex().c_str()); return(0); } else return(-1); @@ -432,8 +432,8 @@ uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std: ((uint8_t *)blockhashp)[i] = opret[i]; for (i=0; i<32; i++) ((uint8_t *)&desttxid)[i] = opret[4 + 32 + i]; - if ( *heightp != 2690 ) - fprintf(stderr," ntzht.%d %s <- txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(txid).GetHex().c_str(),(int32_t)opret.size()); + if ( 0 && *heightp != 2690 ) + fprintf(stderr," ntzht.%d %s <- txid.%s size.%d\n",*heightp,(*blockhashp).GetHex().c_str(),(txid).GetHex().c_str(),(int32_t)opret.size()); return(desttxid); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 210c721b9..374474dd9 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -233,12 +233,12 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 ssMB << mb; std::vector proof(ssMB.begin(), ssMB.end()); ptr->txprooflen = (int32_t)proof.size(); + fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof)); if ( ptr->txprooflen > 0 ) { ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); memcpy(ptr->txproof,&proof[0],ptr->txprooflen); } - //int64_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag); ptr->unspentvalue = CCgettxout(txid,vout,1,1); //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); @@ -291,7 +291,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid fprintf(stderr,"illegal prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); return(-7); } - fprintf(stderr,"%s -> prevht.%d, %s -> nexht.%d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); + //fprintf(stderr,"%s -> prevht.%d, %s -> nexht.%d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); ptr->common.numhdrs = (ptr->common.nextht - ptr->common.prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); @@ -417,7 +417,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwbignum(0,&request[1],sizeof(prevntz),(uint8_t *)&prevntz); iguana_rwbignum(0,&request[1+sizeof(prevntz)],sizeof(nextntz),(uint8_t *)&nextntz); memset(&P,0,sizeof(P)); - fprintf(stderr,"msg prev.%s next.%s\n",prevntz.GetHex().c_str(),nextntz.GetHex().c_str()); + //fprintf(stderr,"msg prev.%s next.%s\n",prevntz.GetHex().c_str(),nextntz.GetHex().c_str()); if ( (slen= NSPV_getntzsproofresp(&P,prevntz,nextntz)) > 0 ) { response.resize(1 + slen); @@ -442,7 +442,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwnum(0,&request[1],sizeof(height),&height); iguana_rwnum(0,&request[1+sizeof(height)],sizeof(vout),&vout); iguana_rwbignum(0,&request[1+sizeof(height)+sizeof(vout)],sizeof(txid),(uint8_t *)&txid); - fprintf(stderr,"got txid %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); + //fprintf(stderr,"got txid %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); memset(&P,0,sizeof(P)); if ( (slen= NSPV_gettxproof(&P,vout,txid,height)) > 0 ) { diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 899a2707b..39c2af809 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -34,10 +34,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) else if ( height != ptr->common.nextht ) return(-5); else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) - { - //fprintf(stderr,"hdr.%s vs blockhash.%s\n",NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]).GetHex().c_str(),blockhash.GetHex().c_str()); return(-6); - } for (i=ptr->common.numhdrs-1; i>0; i--) { blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); @@ -77,7 +74,7 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio } if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) { - fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); + //fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { From ccdc1c8080c0b4b4a0d3080b0cefd1f4a5556d89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 05:13:08 -1100 Subject: [PATCH 323/659] Test --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_superlite.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d8f9745e4..a18c0c363 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -286,7 +286,7 @@ int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nextht),&ptr->nextht); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); - fprintf(stderr,"rwcommon prev.%d next.%d\n",ptr->prevht,ptr->nextht); + //fprintf(stderr,"rwcommon prev.%d next.%d\n",ptr->prevht,ptr->nextht); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 374474dd9..d781e4de0 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -233,7 +233,7 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 ssMB << mb; std::vector proof(ssMB.begin(), ssMB.end()); ptr->txprooflen = (int32_t)proof.size(); - fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof)); + fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); if ( ptr->txprooflen > 0 ) { ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index e3dad5752..533e3f8b8 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -382,7 +382,7 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); - fprintf(stderr,"req txproof %s/v%d at height.%d\n",txid.GetHex().c_str(),vout,height); + //fprintf(stderr,"req txproof %s/v%d at height.%d\n",txid.GetHex().c_str(),vout,height); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i Date: Sun, 7 Jul 2019 05:25:57 -1100 Subject: [PATCH 324/659] Use txproof for txproof --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 39c2af809..99cf14dba 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -83,7 +83,7 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio { std::vector txids; std::vector proof; uint256 proofroot; proof.resize(NSPV_txproofresult.txprooflen); - memcpy(&proof[0],NSPV_txproofresult.tx,NSPV_txproofresult.txprooflen); + memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); proofroot = BitcoinGetProofMerkleRoot(proof,txids); if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) { From 45161da432bffd2e9ce9c1caa846d6937dc5e599 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 05:39:21 -1100 Subject: [PATCH 325/659] Activate validation --- src/komodo_nSPV.h | 3 ++- src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_wallet.h | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a18c0c363..3feeec7d0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -19,7 +19,8 @@ // determine if it makes sense to be scanning mempool for the utxo/spentinfo requests, maybe can add isspent flag to txproof, or just use getspentinfo if broadcast fails -// validate proofs +// pubkeys extract +// headers "sync" // interest calculations are currently just using what is returned, it should calculate it from scratch // need to validate incoming data and update only if it is valid and more recent diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index d781e4de0..4a506cc3e 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -233,7 +233,7 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 ssMB << mb; std::vector proof(ssMB.begin(), ssMB.end()); ptr->txprooflen = (int32_t)proof.size(); - fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); + //fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); if ( ptr->txprooflen > 0 ) { ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 99cf14dba..cfecd2a31 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -94,8 +94,8 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio } else retval = -22; } else retval = -1; } - fprintf(stderr,"NSPV_gettransaction retval would have been %d\n",retval); - return(0); + //fprintf(stderr,"NSPV_gettransaction retval would have been %d\n",retval); + return(retval); } int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) From 4f4db5299b4c89862976f048fc4dadb78600ab45 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 05:46:50 -1100 Subject: [PATCH 326/659] Check for spent utxo --- src/komodo_nSPV.h | 2 -- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3feeec7d0..b0dca61c6 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -17,8 +17,6 @@ // todo: // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) -// determine if it makes sense to be scanning mempool for the utxo/spentinfo requests, maybe can add isspent flag to txproof, or just use getspentinfo if broadcast fails - // pubkeys extract // headers "sync" // interest calculations are currently just using what is returned, it should calculate it from scratch diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index cfecd2a31..74bd61639 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -58,7 +58,7 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio { int32_t offset,retval = 0; NSPV_txproof(vout,txid,height); - if ( NSPV_txproofresult.txid != txid ) + if ( NSPV_txproofresult.txid != txid || NSPV_txproofresult.unspentsatoshis <= 0 ) return(-1); else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) retval = -20; From fdca2066bca46db125b61044a152cbfdac3876c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 05:48:12 -1100 Subject: [PATCH 327/659] +print --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 74bd61639..ce330f604 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -258,7 +258,7 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st fprintf(stderr,"signing error for vini.%d\n",i); return(""); } - } else fprintf(stderr,"couldnt find txid.%s\n",mtx.vin[i].prevout.hash.GetHex().c_str()); + } else fprintf(stderr,"couldnt find txid.%s/v%d or it was spent\n",mtx.vin[i].prevout.hash.GetHex().c_str(),utxovout); // of course much better handling is needed } fprintf(stderr,"sign %d inputs %.8f + interest %.8f -> %d outputs %.8f change %.8f\n",(int32_t)mtx.vin.size(),(double)totalinputs/COIN,(double)interest/COIN,(int32_t)mtx.vout.size(),(double)totaloutputs/COIN,(double)change/COIN); return(EncodeHexTx(mtx)); From 456959ad7e6009a4566802a2f65775301a9107d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 05:49:42 -1100 Subject: [PATCH 328/659] unspentvalue --- src/komodo_nSPV_wallet.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index ce330f604..1666f7deb 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -58,7 +58,7 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio { int32_t offset,retval = 0; NSPV_txproof(vout,txid,height); - if ( NSPV_txproofresult.txid != txid || NSPV_txproofresult.unspentsatoshis <= 0 ) + if ( NSPV_txproofresult.txid != txid || NSPV_txproofresult.unspentvalue <= 0 ) return(-1); else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) retval = -20; @@ -230,7 +230,6 @@ std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,st totalinputs += used[i].satoshis; interest += used[i].extradata; } - //PrecomputedTransactionData txdata(mtx); if ( (totalinputs+interest) >= totaloutputs+2*txfee ) { change = (totalinputs+interest) - (totaloutputs+txfee); From 6762cc3bb80273403d65567dc7d8646b6258a345 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 07:07:23 -1100 Subject: [PATCH 329/659] Debug vers --- src/komodo_nSPV_wallet.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 1666f7deb..25c844dc3 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -94,8 +94,9 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio } else retval = -22; } else retval = -1; } - //fprintf(stderr,"NSPV_gettransaction retval would have been %d\n",retval); - return(retval); + if ( retval != 0 ) + fprintf(stderr,"NSPV_gettransaction retval would have been %d\n",retval); + return(retval*0); } int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) From e6d258234506cc45f4b538cf7d0458f111b765f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 19:33:01 -1100 Subject: [PATCH 330/659] Scan future ntz --- src/komodo_nSPV.h | 6 +++ src/komodo_nSPV_fullnode.h | 88 ++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b0dca61c6..1133bfb7d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -24,6 +24,12 @@ // need to validate incoming data and update only if it is valid and more recent // make sure to sanity check all vector lengths on receipt +// bugs: +// got txproof response 1562526470 size.2112 a9ea92a1bbc68ae850b4bedabcbe60132844e5791ba2678bcba520910f1ad0c6 ht.1432768 +// got ntzs response 1562526471 size.209 bbf7ac47c67b5f84ddeffa5621dae6a9c3e5e8fad59cfc7359be2aa2937bd135 prev.1432750, 8255451aa5a5f8ba8f06ea8f4f83879f346bfd782d72c16d034693d123aa4b68 next.1432760 +// NSPV_gettransaction retval would have been -22 + + #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 4a506cc3e..a8c4cf036 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -21,61 +21,47 @@ #include "notarisationdb.h" -/*uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) +struct NSPV_ntzargs { - uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - memset(&txid,0,sizeof(txid)); - *ntzheightp = 0; - int32_t matchedHeight = ScanNotarisationsDB2(height,symbol,1440,nota); - if ( matchedHeight != 0 ) - { - *ntzheightp = matchedHeight; - txid = nota.first; - } - return(txid); -}*/ + uint256 txid,desttxid,blockhash; + int32_t txidht,ntzheight; +}; -int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height) +int32_t NSPV_notarization_find(struct NSPV_ntzargs *args,int32_t height,int32_t dir) { - int32_t txidht; CTransaction tx; Notarisation nota; char *symbol; std::vector opret; uint256 bhash0,bhash1,hashBlock; + int32_t ntzheight = 0; CTransaction tx; Notarisation nota; char *symbol; std::vector opret; symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - memset(txids,0,sizeof(*txids)*2); - memset(desttxids,0,sizeof(*desttxids)*2); - memset(ntzheights,0,sizeof(*ntzheights)*2); - memset(txidhts,0,sizeof(*txidhts)*2); - if ( (txidht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 ) + memset(*args,0,sizeof(*args)); + if ( (args->txidht= (dir < 0 ? ScanNotarisationsDB : ScanNotarisationsDB2)(height,symbol,1440,nota)) == 0 ) return(-1); - txids[0] = nota.first; - txidhts[0] = txidht; - if ( !GetTransaction(txids[0],tx,hashBlock,false) || tx.vout.size() < 2 ) + args->txid = nota.first; + if ( !GetTransaction(args->txid,tx,hashBlock,false) || tx.vout.size() < 2 ) return(-2); GetOpReturnData(tx.vout[1].scriptPubKey,opret); - //if ( opret.size() >= 32*2+4 ) - desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,opret,txids[0]); + if ( opret.size() >= 32*2+4 ) + args->desttxids = NSPV_opretextract(&args->ntzheight,&args->blockhash,symbol,opret,args->txid); + return(args->ntzheight); +} - /*desttxids[0] = NSPV_opretextract(&ntzheights[0],&bhash0,symbol,E_MARSHAL(ss << nota.second)); - //if ( height != 2668 ) - // fprintf(stderr,"scan.%d -> %s txidht.%d ntzht.%d\n",height,desttxids[0].GetHex().c_str(),txidht,ntzheights[0]); - if ( ntzheights[0] == height-1 ) // offset the +1 from caller +int32_t NSPV_notarized_bracket(struct NSPV_ntzargs *prev,struct NSPV_ntzargs *next,int32_t height) +{ + uint256 bhash; int32_t txidht,ntzht,nextht; + memset(prev,0,sizeof(*prev)); + memset(next,0,sizeof(*next)); + if ( (ntzht= NSPV_notarization_find(prev,height,-1)) < 0 || ntzht > height || ntzht == 0 ) + return(-1); + txidht = height+1; + while ( (ntzht= NSPV_notarization_find(next,txidht,1)) < height ) { - txids[1] = txids[0]; - txidhts[1] = txidhts[0]; - ntzheights[1] = ntzheights[0]; - desttxids[1] = desttxids[0]; - return(0); - }*/ - if ( (txidht= ScanNotarisationsDB2(height,symbol,1440,nota)) != 0 ) - { - txids[1] = nota.first; - txidhts[1] = txidht; - if ( !GetTransaction(txids[1],tx,hashBlock,false) || tx.vout.size() < 2 ) - return(-2); - GetOpReturnData(tx.vout[1].scriptPubKey,opret); - //if ( opret.size() >= 32*2+4 ) - desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,opret,txids[1]); - //desttxids[1] = NSPV_opretextract(&ntzheights[1],&bhash1,symbol,E_MARSHAL(ss << nota.second)); + nextht = next->txidht + 1; + fprintf(stderr,"found forward ntz, but ntzht.%d vs height.%d, txidht.%d -> nextht.%d\n",next->ntzheight,height,txidht,nextht); + memset(next,0,sizeof(*next)); + txidht = nextht; + if ( nextht <= txidht ) // not advancing error + break; + if ( ntzht <= 0 ) + break; } - //fprintf(stderr,"prev.(%s -> ht.%d %s) next.(%s -> ht.%d %s)\n",txids[0].GetHex().c_str(),ntzheights[0],bhash0.GetHex().c_str(),txids[1].GetHex().c_str(),ntzheights[1],bhash1.GetHex().c_str()); return(0); } @@ -91,19 +77,19 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) { - uint256 txids[2],desttxids[2]; int32_t ntzheights[2],txidhts[2]; + struct NSPV_ntzargs prev,next; if ( height < chainActive.LastTip()->GetHeight() ) height++; - if ( komodo_notarized_bracket(txids,txidhts,desttxids,ntzheights,height) == 0 ) + if ( NSPV_notarized_bracket(&prev,&next,height) == 0 ) { - if ( ntzheights[0] != 0 ) + if ( prev.ntzheight != 0 ) { - if ( NSPV_ntzextract(&ptr->prevntz,txids[0],txidhts[0],desttxids[0],ntzheights[0]) < 0 ) + if ( NSPV_ntzextract(&ptr->prevntz,prev.txid,prev.txidht,prev.desttxid,prev.ntzheight) < 0 ) return(-1); } - if ( ntzheights[1] != 0 ) + if ( next.ntzheight != 0 ) { - if ( NSPV_ntzextract(&ptr->nextntz,txids[1],txidhts[1],desttxids[1],ntzheights[1]) < 0 ) + if ( NSPV_ntzextract(&ptr->nextntz,next.txid,next.txidht,next.desttxid,next.ntzheight) < 0 ) return(-1); } } From e21703d6489a4d9edad691413208100c42372ec9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 19:35:07 -1100 Subject: [PATCH 331/659] Syntax --- src/komodo_nSPV_fullnode.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index a8c4cf036..7abec636d 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -29,9 +29,9 @@ struct NSPV_ntzargs int32_t NSPV_notarization_find(struct NSPV_ntzargs *args,int32_t height,int32_t dir) { - int32_t ntzheight = 0; CTransaction tx; Notarisation nota; char *symbol; std::vector opret; + int32_t ntzheight = 0; uint256 hashBlock; CTransaction tx; Notarisation nota; char *symbol; std::vector opret; symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - memset(*args,0,sizeof(*args)); + memset(args,0,sizeof(*args)); if ( (args->txidht= (dir < 0 ? ScanNotarisationsDB : ScanNotarisationsDB2)(height,symbol,1440,nota)) == 0 ) return(-1); args->txid = nota.first; @@ -39,7 +39,7 @@ int32_t NSPV_notarization_find(struct NSPV_ntzargs *args,int32_t height,int32_t return(-2); GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4 ) - args->desttxids = NSPV_opretextract(&args->ntzheight,&args->blockhash,symbol,opret,args->txid); + args->desttxid = NSPV_opretextract(&args->ntzheight,&args->blockhash,symbol,opret,args->txid); return(args->ntzheight); } From 10ac1c2454809a627e3caa397343648ef4f675ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 19:59:26 -1100 Subject: [PATCH 332/659] Display retcodes --- src/komodo_nSPV_wallet.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 25c844dc3..65c5ce068 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -92,11 +92,9 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio } } } else retval = -22; - } else retval = -1; + } else retval = -2; } - if ( retval != 0 ) - fprintf(stderr,"NSPV_gettransaction retval would have been %d\n",retval); - return(retval*0); + return(retval); } int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) @@ -219,9 +217,9 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C return(false); } -std::string NSPV_signtx(CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) +std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) { - CTransaction vintx; std::string hex; uint256 hashBlock; int64_t interest=0,change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n; + CTransaction vintx; std::string hex; uint256 hashBlock; int64_t interest=0,change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n,validation; n = mtx.vout.size(); for (i=0; i NSPV_logintime+NSPV_AUTOLOGOUT ) { result.push_back(Pair("result","error")); @@ -335,7 +335,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a result.push_back(Pair("error","wif expired")); return(result); } - hex = NSPV_signtx(mtx,txfee,opret,used); + hex = NSPV_signtx(retcodes,mtx,txfee,opret,used); if ( hex.size() > 0 ) { if ( DecodeHexTx(tx,hex) != 0 ) @@ -343,6 +343,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a TxToJSON(tx,uint256(),result); result.push_back(Pair("result","success")); result.push_back(Pair("hex",hex)); + result.push_back(Pair("retcodes",retcodes)); } else { @@ -354,6 +355,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a else { result.push_back(Pair("result","error")); + result.push_back(Pair("retcodes",retcodes)); result.push_back(Pair("error","signing error")); } return(result); From 473609a1e4e1e7ce14412893cffe1a961a3c9cd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 20:01:08 -1100 Subject: [PATCH 333/659] Typo --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 65c5ce068..c7ce08054 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -241,7 +241,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf utxovout = mtx.vin[i].prevout.n; validation = NSPV_gettransaction(utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); retcodes.push_back(validation); - if ( validaton != -1 ) // most others are degraded security + if ( validation != -1 ) // most others are degraded security { if ( vintx.vout[utxovout].nValue != used[i].satoshis ) { From a025c5d9e430dff372fd43b75b5a7b6b6c12bd3f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 20:08:51 -1100 Subject: [PATCH 334/659] -print --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 7abec636d..db86348a0 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -54,7 +54,7 @@ int32_t NSPV_notarized_bracket(struct NSPV_ntzargs *prev,struct NSPV_ntzargs *ne while ( (ntzht= NSPV_notarization_find(next,txidht,1)) < height ) { nextht = next->txidht + 1; - fprintf(stderr,"found forward ntz, but ntzht.%d vs height.%d, txidht.%d -> nextht.%d\n",next->ntzheight,height,txidht,nextht); + //fprintf(stderr,"found forward ntz, but ntzht.%d vs height.%d, txidht.%d -> nextht.%d\n",next->ntzheight,height,txidht,nextht); memset(next,0,sizeof(*next)); txidht = nextht; if ( nextht <= txidht ) // not advancing error From a8cc298d5b862c70dbf94afd5816523a9252746a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:20:15 -1100 Subject: [PATCH 335/659] New netinfo tweak bracket --- src/komodo_nSPV.h | 12 +++---- src/komodo_nSPV_fullnode.h | 4 ++- src/komodo_nSPV_superlite.h | 69 +++++++++++++++++-------------------- src/komodo_nSPV_wallet.h | 2 ++ src/wallet/rpcdump.cpp | 11 +++--- 5 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1133bfb7d..4b4b3510a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -24,12 +24,6 @@ // need to validate incoming data and update only if it is valid and more recent // make sure to sanity check all vector lengths on receipt -// bugs: -// got txproof response 1562526470 size.2112 a9ea92a1bbc68ae850b4bedabcbe60132844e5791ba2678bcba520910f1ad0c6 ht.1432768 -// got ntzs response 1562526471 size.209 bbf7ac47c67b5f84ddeffa5621dae6a9c3e5e8fad59cfc7359be2aa2937bd135 prev.1432750, 8255451aa5a5f8ba8f06ea8f4f83879f346bfd782d72c16d034693d123aa4b68 next.1432760 -// NSPV_gettransaction retval would have been -22 - - #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H @@ -223,7 +217,8 @@ struct NSPV_inforesp { struct NSPV_ntz notarization; uint256 blockhash; - int32_t height,pad32; + int32_t height,hdrheight; + struct NSPV_equihdr H; }; int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp *ptr) @@ -232,7 +227,8 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += NSPV_rwntz(rwflag,&serialized[len],&ptr->notarization); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->blockhash),(uint8_t *)&ptr->blockhash); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); + len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index db86348a0..c2e4b4e52 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -32,7 +32,9 @@ int32_t NSPV_notarization_find(struct NSPV_ntzargs *args,int32_t height,int32_t int32_t ntzheight = 0; uint256 hashBlock; CTransaction tx; Notarisation nota; char *symbol; std::vector opret; symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(args,0,sizeof(*args)); - if ( (args->txidht= (dir < 0 ? ScanNotarisationsDB : ScanNotarisationsDB2)(height,symbol,1440,nota)) == 0 ) + if ( dir > 0 ) + height += 10; + if ( (args->txidht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 ) return(-1); args->txid = nota.first; if ( !GetTransaction(args->txid,tx,hashBlock,false) || tx.vout.size() < 2 ) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 533e3f8b8..4b791880b 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -105,7 +105,27 @@ UniValue NSPV_ntz_json(struct NSPV_ntz *ptr) return(result); } -UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr) +UniValue NSPV_header_json(struct NSPV_equihdr *hdr,int32_t height) +{ + UniValue item(UniValue::VOBJ); + item.push_back(Pair("height",(int64_t)height)); + item.push_back(Pair("blockhash",NSPV_hdrhash(hdr).GetHex())); + item.push_back(Pair("hashPrevBlock",hdr->hashPrevBlock.GetHex())); + item.push_back(Pair("hashMerkleRoot",hdr->hashMerkleRoot.GetHex())); + item.push_back(Pair("nTime",(int64_t)hdr->nTime)); + item.push_back(Pair("nBits",(int64_t)hdr->nBits)); + return(item); +} + +UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs,int32_t height) +{ + UniValue array(UniValue::VARR); int32_t i; + for (i=0; iheight)); result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); + result.push_back(Pair("hdr",NSPV_header_json(&ptr->H))); return(result); } @@ -165,23 +186,6 @@ UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr) return(result); } -UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs,int32_t height) -{ - UniValue array(UniValue::VARR); int32_t i; - for (i=0; i>1) != 0 ) { - //fprintf(stderr,"issue getinfo\n"); - if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + for (i=0; i>1); - } slen = (int32_t)strlen(coinaddr); msg[len++] = NSPV_UTXOS; msg[len++] = slen; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index c7ce08054..9ab477e3e 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -383,8 +383,10 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages { if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) { + int32_t reqht = 0; len = 0; msg[len++] = NSPV_INFO; + len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); } } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index e13276960..0aac30799 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -972,7 +972,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) return EncodeViewingKey(vk); } -UniValue NSPV_getinfo_json(); +UniValue NSPV_getinfo_req(int32_t reqht); UniValue NSPV_login(char *wifstr); UniValue NSPV_logout(); UniValue NSPV_addressutxos(char *coinaddr); @@ -987,9 +987,12 @@ extern std::string NSPV_address; UniValue nspv_getinfo(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() != 0 ) - throw runtime_error("nspv_getinfo\n"); - return(NSPV_getinfo_json()); + int32_t reqht = 0; + if ( fHelp || params.size() > 1 ) + throw runtime_error("nspv_getinfo [hdrheight]\n"); + if ( params.size() == 0 ) + reqht = atoi((char *)params[0].get_str().c_str()); + return(NSPV_getinfo_req(reqht)); } UniValue nspv_logout(const UniValue& params, bool fHelp) From 72884c3722bb799a08126603b4c7de19136c971e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:21:07 -1100 Subject: [PATCH 336/659] +print --- src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index c2e4b4e52..9fc6157e0 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -56,7 +56,7 @@ int32_t NSPV_notarized_bracket(struct NSPV_ntzargs *prev,struct NSPV_ntzargs *ne while ( (ntzht= NSPV_notarization_find(next,txidht,1)) < height ) { nextht = next->txidht + 1; - //fprintf(stderr,"found forward ntz, but ntzht.%d vs height.%d, txidht.%d -> nextht.%d\n",next->ntzheight,height,txidht,nextht); +fprintf(stderr,"found forward ntz, but ntzht.%d vs height.%d, txidht.%d -> nextht.%d\n",next->ntzheight,height,txidht,nextht); memset(next,0,sizeof(*next)); txidht = nextht; if ( nextht <= txidht ) // not advancing error diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 9ab477e3e..6bc3c0b4e 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -74,7 +74,7 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio } if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) { - //fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); +fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { From db687d05d03ca61cbf3cd6daa70507a0009af927 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:23:35 -1100 Subject: [PATCH 337/659] Fix --- src/komodo_nSPV_fullnode.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 9fc6157e0..8c213e370 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -47,7 +47,7 @@ int32_t NSPV_notarization_find(struct NSPV_ntzargs *args,int32_t height,int32_t int32_t NSPV_notarized_bracket(struct NSPV_ntzargs *prev,struct NSPV_ntzargs *next,int32_t height) { - uint256 bhash; int32_t txidht,ntzht,nextht; + uint256 bhash; int32_t txidht,ntzht,nextht,i=0; memset(prev,0,sizeof(*prev)); memset(next,0,sizeof(*next)); if ( (ntzht= NSPV_notarization_find(prev,height,-1)) < 0 || ntzht > height || ntzht == 0 ) @@ -55,14 +55,14 @@ int32_t NSPV_notarized_bracket(struct NSPV_ntzargs *prev,struct NSPV_ntzargs *ne txidht = height+1; while ( (ntzht= NSPV_notarization_find(next,txidht,1)) < height ) { - nextht = next->txidht + 1; + nextht = next->txidht + 10*i; fprintf(stderr,"found forward ntz, but ntzht.%d vs height.%d, txidht.%d -> nextht.%d\n",next->ntzheight,height,txidht,nextht); memset(next,0,sizeof(*next)); txidht = nextht; - if ( nextht <= txidht ) // not advancing error - break; if ( ntzht <= 0 ) break; + if ( i++ > 10 ) + break; } return(0); } From fc20386d8d5a5a68f5b5289a84417ee62a133caa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:24:42 -1100 Subject: [PATCH 338/659] Syntax --- src/komodo_nSPV_superlite.h | 2 +- src/komodo_nSPV_wallet.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 4b791880b..c5ac37159 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -142,7 +142,7 @@ UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr) result.push_back(Pair("height",(int64_t)ptr->height)); result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); - result.push_back(Pair("hdr",NSPV_header_json(&ptr->H))); + result.push_back(Pair("hdr",NSPV_header_json(&ptr->H,ptr->hdrheight))); return(result); } diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 6bc3c0b4e..1f47a6469 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -286,8 +286,6 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a result.push_back(Pair("error","invalid destaddr")); return(result); } - if ( NSPV_inforesult.height == 0 ) - NSPV_getinfo_json(); if ( NSPV_inforesult.height == 0 ) { result.push_back(Pair("result","error")); From 5fc26ebcbe6b8491a93ae6a12b94a35dcc4a5de3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:26:48 -1100 Subject: [PATCH 339/659] Syntax --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index c5ac37159..48420f312 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -283,7 +283,7 @@ UniValue NSPV_getinfo_req(int32_t reqht) { usleep(NSPV_POLLMICROS); if ( NSPV_inforesult.height != 0 ) - return(_NSPV_getinfo_json(&NSPV_inforesult)); + return(NSPV_getinfo_json(&NSPV_inforesult,NSPV_inforesult.hdrheight)); } } memset(&I,0,sizeof(I)); From 99fc3cfd8afd2afb8bad1a454839ac4fa48e3f5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:30:03 -1100 Subject: [PATCH 340/659] Syntax --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 48420f312..41ec3c571 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -283,7 +283,7 @@ UniValue NSPV_getinfo_req(int32_t reqht) { usleep(NSPV_POLLMICROS); if ( NSPV_inforesult.height != 0 ) - return(NSPV_getinfo_json(&NSPV_inforesult,NSPV_inforesult.hdrheight)); + return(NSPV_getinfo_json(&NSPV_inforesult)); } } memset(&I,0,sizeof(I)); From 640cb30c56af4d4cd02d1ca859ba5512a155f816 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:37:42 -1100 Subject: [PATCH 341/659] Prints --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_fullnode.h | 3 +++ src/wallet/rpcdump.cpp | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4b4b3510a..9ffd67030 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -229,6 +229,7 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); + fprintf(stderr,"hdr rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 8c213e370..26f0f44dc 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -333,11 +333,14 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_inforesp I; + iguana_rwnum(0,&request[1],sizeof(height),&height); + fprintf(stderr,"request height.%d\n",height); memset(&I,0,sizeof(I)); if ( (slen= NSPV_getinfo(&I)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_INFORESP; + fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { pfrom->PushMessage("nSPV",response); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 0aac30799..071e3d8a7 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -990,7 +990,7 @@ UniValue nspv_getinfo(const UniValue& params, bool fHelp) int32_t reqht = 0; if ( fHelp || params.size() > 1 ) throw runtime_error("nspv_getinfo [hdrheight]\n"); - if ( params.size() == 0 ) + if ( params.size() == 1 ) reqht = atoi((char *)params[0].get_str().c_str()); return(NSPV_getinfo_req(reqht)); } From a3cf4b19517b05751d873976f8c3e8d49edf9cac Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:39:49 -1100 Subject: [PATCH 342/659] Return reqhdr --- src/komodo_nSPV_fullnode.h | 48 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 26f0f44dc..d555d6468 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -98,7 +98,27 @@ int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) return(sizeof(*ptr)); } -int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) +int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) +{ + CBlockIndex *pindex; + if ( (pindex= komodo_chainactive(height)) != 0 ) + { + hdr->nVersion = pindex->nVersion; + if ( pindex->pprev == 0 ) + return(-1); + hdr->hashPrevBlock = pindex->pprev->GetBlockHash(); + hdr->hashMerkleRoot = pindex->hashMerkleRoot; + hdr->hashFinalSaplingRoot = pindex->hashFinalSaplingRoot; + hdr->nTime = pindex->nTime; + hdr->nBits = pindex->nBits; + hdr->nNonce = pindex->nNonce; + memcpy(hdr->nSolution,&pindex->nSolution[0],sizeof(hdr->nSolution)); + return(sizeof(*hdr)); + } + return(-1); +} + +int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) { int32_t prevMoMheight,len = 0; CBlockIndex *pindex; struct NSPV_ntzsresp pair; if ( (pindex= chainActive.LastTip()) != 0 ) @@ -108,6 +128,10 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) if ( NSPV_getntzsresp(&pair,ptr->height-1) < 0 ) return(-1); ptr->notarization = pair.prevntz; + if ( reqheight == 0 ) + reqheight = pindex->nHeight; + if ( NSPV_setequihdr(&ptr->H,reqheight) < 0 ) + return(-1); return(sizeof(*ptr)); } else return(-1); } @@ -235,26 +259,6 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 return(-1); } -int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) -{ - CBlockIndex *pindex; - if ( (pindex= komodo_chainactive(height)) != 0 ) - { - hdr->nVersion = pindex->nVersion; - if ( pindex->pprev == 0 ) - return(-1); - hdr->hashPrevBlock = pindex->pprev->GetBlockHash(); - hdr->hashMerkleRoot = pindex->hashMerkleRoot; - hdr->hashFinalSaplingRoot = pindex->hashFinalSaplingRoot; - hdr->nTime = pindex->nTime; - hdr->nBits = pindex->nBits; - hdr->nNonce = pindex->nNonce; - memcpy(hdr->nSolution,&pindex->nSolution[0],sizeof(hdr->nSolution)); - return(sizeof(*hdr)); - } - return(-1); -} - int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid,uint256 nextntztxid) { int32_t i; uint256 hashBlock,bhash0,bhash1,desttxid0,desttxid1; CTransaction tx; @@ -336,7 +340,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwnum(0,&request[1],sizeof(height),&height); fprintf(stderr,"request height.%d\n",height); memset(&I,0,sizeof(I)); - if ( (slen= NSPV_getinfo(&I)) > 0 ) + if ( (slen= NSPV_getinfo(&I,height)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_INFORESP; From c3e92dba4f59ace5cd8ebe841f09a34d897ab44b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:42:49 -1100 Subject: [PATCH 343/659] Syntax --- src/komodo_nSPV_fullnode.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index d555d6468..26515993f 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -129,7 +129,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) return(-1); ptr->notarization = pair.prevntz; if ( reqheight == 0 ) - reqheight = pindex->nHeight; + reqheight = pindex->GetHeight(); if ( NSPV_setequihdr(&ptr->H,reqheight) < 0 ) return(-1); return(sizeof(*ptr)); @@ -324,7 +324,7 @@ int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request { - int32_t len,slen,ind; std::vector response; uint32_t timestamp = (uint32_t)time(NULL); + int32_t len,slen,ind,reqheight; std::vector response; uint32_t timestamp = (uint32_t)time(NULL); if ( (len= request.size()) > 0 ) { if ( (ind= request[0]>>1) >= sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes) ) @@ -337,8 +337,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_inforesp I; - iguana_rwnum(0,&request[1],sizeof(height),&height); - fprintf(stderr,"request height.%d\n",height); + iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); + fprintf(stderr,"request height.%d\n",reqheight); memset(&I,0,sizeof(I)); if ( (slen= NSPV_getinfo(&I,height)) > 0 ) { From 9c020edb521cefa6ae9e57c0894788f5e3a65d4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:44:32 -1100 Subject: [PATCH 344/659] Syntax --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 26515993f..9b89c6b7e 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -340,7 +340,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); fprintf(stderr,"request height.%d\n",reqheight); memset(&I,0,sizeof(I)); - if ( (slen= NSPV_getinfo(&I,height)) > 0 ) + if ( (slen= NSPV_getinfo(&I,reqheight)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_INFORESP; From 96bb0c21d547b3fa403901e0d69451a89c3d4dce Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 21:58:07 -1100 Subject: [PATCH 345/659] Fixes --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9ffd67030..d625d387a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -229,7 +229,7 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); - fprintf(stderr,"hdr rwlen.%d\n",len); + //fprintf(stderr,"hdr rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 9b89c6b7e..b496a6fb1 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -129,7 +129,8 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) return(-1); ptr->notarization = pair.prevntz; if ( reqheight == 0 ) - reqheight = pindex->GetHeight(); + reqheight = ptr->height; + ptr->hdrheight = reqheight; if ( NSPV_setequihdr(&ptr->H,reqheight) < 0 ) return(-1); return(sizeof(*ptr)); @@ -338,13 +339,13 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { struct NSPV_inforesp I; iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); - fprintf(stderr,"request height.%d\n",reqheight); + //fprintf(stderr,"request height.%d\n",reqheight); memset(&I,0,sizeof(I)); if ( (slen= NSPV_getinfo(&I,reqheight)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_INFORESP; - fprintf(stderr,"slen.%d\n",slen); + //fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { pfrom->PushMessage("nSPV",response); From 6b7ebf2d9f27db663ce6ce1790a30040c7bf8c80 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 22:02:04 -1100 Subject: [PATCH 346/659] Set fields --- src/komodo_nSPV_wallet.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 1f47a6469..47edab3b3 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -381,7 +381,8 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages { if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) { - int32_t reqht = 0; + int32_t reqht; + reqht = 0; len = 0; msg[len++] = NSPV_INFO; len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); From 2061bf4130bec4f29b6cb63fabf37ea774e82db5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 22:03:29 -1100 Subject: [PATCH 347/659] Default reqheight --- src/komodo_nSPV_fullnode.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index b496a6fb1..298a96ff8 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -338,7 +338,9 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_inforesp I; - iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); + if ( len == 1+sizeof(reqheight) ) + iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight); + else reqheight = 0; //fprintf(stderr,"request height.%d\n",reqheight); memset(&I,0,sizeof(I)); if ( (slen= NSPV_getinfo(&I,reqheight)) > 0 ) From d35951cb1bef71c1b8c435af19a86f600e171f9b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 22:09:11 -1100 Subject: [PATCH 348/659] Initial handling of non-notarised --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 47edab3b3..bc619b40f 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -65,7 +65,7 @@ int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransactio else { NSPV_notarizations(height); // gets the prev and next notarizations - if ( NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height ) + if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) { fprintf(stderr,"issue manual bracket\n"); NSPV_notarizations(height-1); From dcbf1539a27e5fc568fb6ce44c242c6f47db5834 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 22:25:59 -1100 Subject: [PATCH 349/659] Rearrange code --- src/komodo_nSPV_superlite.h | 79 +++++++++++++++++++++++++++++++++++++ src/komodo_nSPV_wallet.h | 79 +------------------------------------ 2 files changed, 80 insertions(+), 78 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 41ec3c571..3710f04ac 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -445,6 +445,85 @@ UniValue NSPV_broadcast(char *hex) return(NSPV_broadcast_json(&B,txid)); } +int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) +{ + int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; + if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) + return(-1); + else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) + return(-2); + else if ( tx.GetHash() != ptr->nexttxid ) + return(-3); + else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 ) + return(-4); + else if ( height != ptr->common.nextht ) + return(-5); + else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) + return(-6); + for (i=ptr->common.numhdrs-1; i>0; i--) + { + blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); + if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) + return(-i-12); + } + if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) + return(-7); + else if ( tx.GetHash() != ptr->prevtxid ) + return(-8); + else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 ) + return(-9); + else if ( height != ptr->common.prevht ) + return(-10); + else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) + return(-11); + return(0); +} + +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx) +{ + int32_t offset,retval = 0; + NSPV_txproof(vout,txid,height); + if ( NSPV_txproofresult.txid != txid || NSPV_txproofresult.unspentvalue <= 0 ) + return(-1); + else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) + retval = -20; + else if ( skipvalidation == 0 ) + { + NSPV_notarizations(height); // gets the prev and next notarizations + if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) + { + fprintf(stderr,"issue manual bracket\n"); + NSPV_notarizations(height-1); + NSPV_notarizations(height+1); + NSPV_notarizations(height); // gets the prev and next notarizations + } + if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) + { + fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); + offset = (height - NSPV_ntzsresult.prevntz.height); + if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) + { + NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); + if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) + { + std::vector txids; std::vector proof; uint256 proofroot; + proof.resize(NSPV_txproofresult.txprooflen); + memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); + proofroot = BitcoinGetProofMerkleRoot(proof,txids); + if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) + { + fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",NSPV_txproofresult.txprooflen,proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); + retval = -23; + } + } + } else retval = -22; + } else retval = -2; + } + return(retval); +} + +// called from async message processing + void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response { int32_t len; uint32_t timestamp = (uint32_t)time(NULL); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index bc619b40f..e62fa4430 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -20,83 +20,6 @@ // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_spend extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); -int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) -{ - int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; - if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) - return(-1); - else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) - return(-2); - else if ( tx.GetHash() != ptr->nexttxid ) - return(-3); - else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 ) - return(-4); - else if ( height != ptr->common.nextht ) - return(-5); - else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) - return(-6); - for (i=ptr->common.numhdrs-1; i>0; i--) - { - blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); - if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) - return(-i-12); - } - if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) - return(-7); - else if ( tx.GetHash() != ptr->prevtxid ) - return(-8); - else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 ) - return(-9); - else if ( height != ptr->common.prevht ) - return(-10); - else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) - return(-11); - return(0); -} - -int32_t NSPV_gettransaction(int32_t vout,uint256 txid,int32_t height,CTransaction &tx) -{ - int32_t offset,retval = 0; - NSPV_txproof(vout,txid,height); - if ( NSPV_txproofresult.txid != txid || NSPV_txproofresult.unspentvalue <= 0 ) - return(-1); - else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) - retval = -20; - else - { - NSPV_notarizations(height); // gets the prev and next notarizations - if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) - { - fprintf(stderr,"issue manual bracket\n"); - NSPV_notarizations(height-1); - NSPV_notarizations(height+1); - NSPV_notarizations(height); // gets the prev and next notarizations - } - if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) - { -fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); - offset = (height - NSPV_ntzsresult.prevntz.height); - if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) - { - NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); - if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) - { - std::vector txids; std::vector proof; uint256 proofroot; - proof.resize(NSPV_txproofresult.txprooflen); - memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); - proofroot = BitcoinGetProofMerkleRoot(proof,txids); - if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) - { - fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",NSPV_txproofresult.txprooflen,proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); - retval = -23; - } - } - } else retval = -22; - } else retval = -2; - } - return(retval); -} - int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) { int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; @@ -239,7 +162,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf for (i=0; i Date: Sun, 7 Jul 2019 22:37:58 -1100 Subject: [PATCH 350/659] Guard getinfo HDR --- src/komodo_nSPV_superlite.h | 116 +++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 3710f04ac..5e1014dae 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -37,6 +37,64 @@ struct NSPV_ntzsproofresp NSPV_ntzsproofresult; struct NSPV_txproof NSPV_txproofresult; struct NSPV_broadcastresp NSPV_broadcastresult; +// komodo_nSPVresp is called from async message processing + +void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response +{ + struct NSPV_inforesp I; int32_t len; uint32_t timestamp = (uint32_t)time(NULL); + if ( (len= response.size()) > 0 ) + { + switch ( response[0] ) + { + case NSPV_INFORESP: + I = NSPV_inforesult; + NSPV_inforesp_purge(&NSPV_inforesult); + NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); + if ( NSPV_inforesult.height < I.height ) + { + fprintf(stderr,"got old info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status + NSPV_inforesp_purge(&NSPV_inforesult); + NSPV_inforesult = I; + } // else update headers state + break; + case NSPV_UTXOSRESP: + NSPV_utxosresp_purge(&NSPV_utxosresult); + NSPV_rwutxosresp(0,&response[1],&NSPV_utxosresult); + fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos list + break; + case NSPV_NTZSRESP: + NSPV_ntzsresp_purge(&NSPV_ntzsresult); + NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); + fprintf(stderr,"got ntzs response %u size.%d %s prev.%d, %s next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.height); + break; + case NSPV_NTZSPROOFRESP: + NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); + NSPV_rwntzsproofresp(0,&response[1],&NSPV_ntzsproofresult); + fprintf(stderr,"got ntzproof response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsproofresult.common.prevht,NSPV_ntzsproofresult.common.nextht); + break; + case NSPV_TXPROOFRESP: + NSPV_txproof_purge(&NSPV_txproofresult); + NSPV_rwtxproof(0,&response[1],&NSPV_txproofresult); + fprintf(stderr,"got txproof response %u size.%d %s ht.%d\n",timestamp,(int32_t)response.size(),NSPV_txproofresult.txid.GetHex().c_str(),NSPV_txproofresult.height); + break; + case NSPV_SPENTINFORESP: + NSPV_spentinfo_purge(&NSPV_spentresult); + NSPV_rwspentinfo(0,&response[1],&NSPV_spentresult); + fprintf(stderr,"got spentinfo response %u size.%d\n",timestamp,(int32_t)response.size()); + break; + case NSPV_BROADCASTRESP: + NSPV_broadcast_purge(&NSPV_broadcastresult); + NSPV_rwbroadcastresp(0,&response[1],&NSPV_broadcastresult); + fprintf(stderr,"got broadcast response %u size.%d %s retcode.%d\n",timestamp,(int32_t)response.size(),NSPV_broadcastresult.txid.GetHex().c_str(),NSPV_broadcastresult.retcode); + break; + default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); + break; + } + } +} + +// superlite message issuing + CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t flag = 0; uint32_t timestamp = (uint32_t)time(NULL); @@ -322,8 +380,8 @@ UniValue NSPV_addressutxos(char *coinaddr) UniValue NSPV_notarizations(int32_t height) { uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsresp N; - if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) - return(NSPV_ntzs_json(&NSPV_ntzsresult)); + //if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) + // return(NSPV_ntzs_json(&NSPV_ntzsresult)); msg[len++] = NSPV_NTZS; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) @@ -395,8 +453,8 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) UniValue NSPV_spentinfo(uint256 txid,int32_t vout) { uint8_t msg[64]; int32_t i,len = 0; struct NSPV_spentinfo I; - if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) - return(NSPV_spentinfo_json(&NSPV_spentresult)); + //if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) + // return(NSPV_spentinfo_json(&NSPV_spentresult)); msg[len++] = NSPV_SPENTINFO; len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); @@ -522,54 +580,4 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int return(retval); } -// called from async message processing - -void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response -{ - int32_t len; uint32_t timestamp = (uint32_t)time(NULL); - if ( (len= response.size()) > 0 ) - { - switch ( response[0] ) - { - case NSPV_INFORESP: - NSPV_inforesp_purge(&NSPV_inforesult); - NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); - //fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status - break; - case NSPV_UTXOSRESP: - NSPV_utxosresp_purge(&NSPV_utxosresult); - NSPV_rwutxosresp(0,&response[1],&NSPV_utxosresult); - fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos list - break; - case NSPV_NTZSRESP: - NSPV_ntzsresp_purge(&NSPV_ntzsresult); - NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); - fprintf(stderr,"got ntzs response %u size.%d %s prev.%d, %s next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.height); - break; - case NSPV_NTZSPROOFRESP: - NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); - NSPV_rwntzsproofresp(0,&response[1],&NSPV_ntzsproofresult); - fprintf(stderr,"got ntzproof response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsproofresult.common.prevht,NSPV_ntzsproofresult.common.nextht); - break; - case NSPV_TXPROOFRESP: - NSPV_txproof_purge(&NSPV_txproofresult); - NSPV_rwtxproof(0,&response[1],&NSPV_txproofresult); - fprintf(stderr,"got txproof response %u size.%d %s ht.%d\n",timestamp,(int32_t)response.size(),NSPV_txproofresult.txid.GetHex().c_str(),NSPV_txproofresult.height); - break; - case NSPV_SPENTINFORESP: - NSPV_spentinfo_purge(&NSPV_spentresult); - NSPV_rwspentinfo(0,&response[1],&NSPV_spentresult); - fprintf(stderr,"got spentinfo response %u size.%d\n",timestamp,(int32_t)response.size()); - break; - case NSPV_BROADCASTRESP: - NSPV_broadcast_purge(&NSPV_broadcastresult); - NSPV_rwbroadcastresp(0,&response[1],&NSPV_broadcastresult); - fprintf(stderr,"got broadcast response %u size.%d %s retcode.%d\n",timestamp,(int32_t)response.size(),NSPV_broadcastresult.txid.GetHex().c_str(),NSPV_broadcastresult.retcode); - break; - default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); - break; - } - } -} - #endif // KOMODO_NSPVSUPERLITE_H From 48e0e4fe856ba1a88538504b7c1202f0d75d516d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 22:45:14 -1100 Subject: [PATCH 351/659] -print --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 298a96ff8..e71d47d07 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -56,7 +56,7 @@ int32_t NSPV_notarized_bracket(struct NSPV_ntzargs *prev,struct NSPV_ntzargs *ne while ( (ntzht= NSPV_notarization_find(next,txidht,1)) < height ) { nextht = next->txidht + 10*i; -fprintf(stderr,"found forward ntz, but ntzht.%d vs height.%d, txidht.%d -> nextht.%d\n",next->ntzheight,height,txidht,nextht); +//fprintf(stderr,"found forward ntz, but ntzht.%d vs height.%d, txidht.%d -> nextht.%d\n",next->ntzheight,height,txidht,nextht); memset(next,0,sizeof(*next)); txidht = nextht; if ( ntzht <= 0 ) From ddd2f1fb0e9bed3392ce11a179b1f4d6657d5c37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jul 2019 22:54:08 -1100 Subject: [PATCH 352/659] HDR -> header --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5e1014dae..585784eec 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -200,7 +200,7 @@ UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr) result.push_back(Pair("height",(int64_t)ptr->height)); result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); - result.push_back(Pair("hdr",NSPV_header_json(&ptr->H,ptr->hdrheight))); + result.push_back(Pair("header",NSPV_header_json(&ptr->H,ptr->hdrheight))); return(result); } From aac97b50995426a142cf57327c52cff0408c15a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 00:13:05 -1100 Subject: [PATCH 353/659] +print --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_wallet.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d625d387a..4fb2742a6 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -15,7 +15,6 @@ ******************************************************************************/ // todo: -// make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) // pubkeys extract // headers "sync" @@ -23,6 +22,7 @@ // need to validate incoming data and update only if it is valid and more recent // make sure to sanity check all vector lengths on receipt +// make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index e62fa4430..df54fc627 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -111,11 +111,11 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 remains -= up->satoshis; utxos[ind] = utxos[--n]; memset(&utxos[n],0,sizeof(utxos[n])); - //fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); + fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break; } - //fprintf(stderr,"totalinputs %.8f vs total %.8f\n",(double)totalinputs/COIN,(double)total/COIN); + fprintf(stderr,"totalinputs %.8f vs total %.8f\n",(double)totalinputs/COIN,(double)total/COIN); if ( totalinputs >= total ) return(totalinputs); return(0); From 36a0e0a9c23accd6196b17df28704b5d5e6d56af Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 00:13:44 -1100 Subject: [PATCH 354/659] +print --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index df54fc627..d748e4d57 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -85,7 +85,7 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 utxos[n++] = ptr[i]; } remains = total; - //fprintf(stderr,"n.%d for total %.8f\n",n,(double)total/COIN); + fprintf(stderr,"threshold %.8f n.%d for total %.8f\n",(double)threshold/COIN,n,(double)total/COIN); for (i=0; i0; i++) { below = above = 0; From a2b6e876af282301f6ffcc0c3ec94a61e1a873aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 00:17:55 -1100 Subject: [PATCH 355/659] Fix utxo selection bug --- src/komodo_nSPV_wallet.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index d748e4d57..485d05b9f 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -81,11 +81,11 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 else threshold = total; for (i=0; i threshold ) + if ( num < NSPV_MAXVINS || ptr[i].satoshis > threshold ) utxos[n++] = ptr[i]; } remains = total; - fprintf(stderr,"threshold %.8f n.%d for total %.8f\n",(double)threshold/COIN,n,(double)total/COIN); + //fprintf(stderr,"threshold %.8f n.%d for total %.8f\n",(double)threshold/COIN,n,(double)total/COIN); for (i=0; i0; i++) { below = above = 0; @@ -115,7 +115,7 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 if ( totalinputs >= total || (i+1) >= maxinputs ) break; } - fprintf(stderr,"totalinputs %.8f vs total %.8f\n",(double)totalinputs/COIN,(double)total/COIN); + //fprintf(stderr,"totalinputs %.8f vs total %.8f\n",(double)totalinputs/COIN,(double)total/COIN); if ( totalinputs >= total ) return(totalinputs); return(0); From e80685bc2d98c539aa4dff5fd1f41ea089995736 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 00:27:03 -1100 Subject: [PATCH 356/659] Retry loop --- src/komodo_nSPV_superlite.h | 41 ++++++++++++++++++++++++++----------- src/wallet/rpcdump.cpp | 2 +- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 585784eec..3caf8473e 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -97,24 +97,41 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { - int32_t flag = 0; uint32_t timestamp = (uint32_t)time(NULL); - if ( pnode == 0 ) + int32_t iter,num; CNode *firstpnode = 0; uint32_t timestamp = (uint32_t)time(NULL); + while ( pnode == 0 ) { LOCK(cs_vNodes); - BOOST_FOREACH(CNode *ptr,vNodes) + num = 0; + for (iter=0; iter<2; iter++) { - if ( ptr->prevtimes[ind] > timestamp ) - ptr->prevtimes[ind] = 0; - if ( ptr->hSocket == INVALID_SOCKET ) - continue; - if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) + BOOST_FOREACH(CNode *ptr,vNodes) { - flag = 1; - pnode = ptr; + if ( ptr->prevtimes[ind] > timestamp ) + ptr->prevtimes[ind] = 0; + if ( ptr->hSocket == INVALID_SOCKET ) + continue; + if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) + { + if ( firstpnode == 0 ) + firstpnode = ptr; + if ( iter != 0 ) + { + if ( num == 1 || (rand() % num) == 0 ) + { + pnode = ptr; + break; + } + } else num++; + } //else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); + } + if ( iter == 0 && num == 0 ) break; - } //else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); + if ( pnode == 0 ) + pnode = firstpnode; } - } else flag = 1; + if ( pnode != 0 && time(NULL) > timestamp+2 ) + break; + } if ( pnode != 0 ) { std::vector request; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 071e3d8a7..b197b73b0 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1071,7 +1071,7 @@ UniValue nspv_spend(const UniValue& params, bool fHelp) if ( NSPV_address.size() == 0 ) throw runtime_error("to nspv_send you need an active nspv_login\n"); satoshis = atof(params[1].get_str().c_str())*COIN + 0.0000000049; - fprintf(stderr,"satoshis.%lld from %.8f\n",(long long)satoshis,atof(params[1].get_str().c_str())); + //fprintf(stderr,"satoshis.%lld from %.8f\n",(long long)satoshis,atof(params[1].get_str().c_str())); if ( satoshis < 1000 ) throw runtime_error("amount too small\n"); return(NSPV_spend((char *)NSPV_address.c_str(),(char *)params[0].get_str().c_str(),satoshis)); From d43ef615ff22c8f94e56a5271fa22cef0e1730ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 00:34:55 -1100 Subject: [PATCH 357/659] Rand selection of peer --- src/komodo_nSPV_superlite.h | 48 ++++++++++++++----------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 3caf8473e..5210f7f87 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -97,41 +97,29 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { - int32_t iter,num; CNode *firstpnode = 0; uint32_t timestamp = (uint32_t)time(NULL); - while ( pnode == 0 ) + int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL); + if ( pnode == 0 ) { + memset(pnodes,0,sizeof(pnodes)); LOCK(cs_vNodes); - num = 0; - for (iter=0; iter<2; iter++) + n = 0; + BOOST_FOREACH(CNode *ptr,vNodes) { - BOOST_FOREACH(CNode *ptr,vNodes) + if ( ptr->prevtimes[ind] > timestamp ) + ptr->prevtimes[ind] = 0; + if ( ptr->hSocket == INVALID_SOCKET ) + continue; + if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) { - if ( ptr->prevtimes[ind] > timestamp ) - ptr->prevtimes[ind] = 0; - if ( ptr->hSocket == INVALID_SOCKET ) - continue; - if ( (ptr->nServices & mask) == mask && timestamp > ptr->prevtimes[ind] ) - { - if ( firstpnode == 0 ) - firstpnode = ptr; - if ( iter != 0 ) - { - if ( num == 1 || (rand() % num) == 0 ) - { - pnode = ptr; - break; - } - } else num++; - } //else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); - } - if ( iter == 0 && num == 0 ) - break; - if ( pnode == 0 ) - pnode = firstpnode; + flag = 1; + pnodes[n++] = ptr; + if ( n == sizeof(pnodes)/sizeof(*pnodes) ) + break; + } // else fprintf(stderr,"nServices %llx vs mask %llx, t%u vs %u, ind.%d\n",(long long)ptr->nServices,(long long)mask,timestamp,ptr->prevtimes[ind],ind); } - if ( pnode != 0 && time(NULL) > timestamp+2 ) - break; - } + if ( n > 0 ) + pnode = pnodes[rand() % n]; + } else flag = 1; if ( pnode != 0 ) { std::vector request; From dfe68a9e2897088214c2e8f933060bb37d2077ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 00:41:54 -1100 Subject: [PATCH 358/659] 3 items --- src/komodo_nSPV_superlite.h | 23 +++++++++++++++-------- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5210f7f87..c1494f721 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -336,10 +336,11 @@ UniValue NSPV_login(char *wifstr) UniValue NSPV_getinfo_req(int32_t reqht) { - uint8_t msg[64]; int32_t i,len = 0; struct NSPV_inforesp I; + uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_inforesp I; NSPV_inforesp_purge(&NSPV_inforesult); msg[len++] = NSPV_INFO; len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); + for (iter=0; iter<3; iter++,sleep(1)); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i= height ) // return(NSPV_ntzs_json(&NSPV_ntzsresult)); msg[len++] = NSPV_NTZS; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); + for (iter=0; iter<3; iter++,sleep(1)); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i> 1; data = (uint8_t *)malloc(n); decode_hex(data,n,hex); @@ -490,6 +496,7 @@ UniValue NSPV_broadcast(char *hex) memcpy(&msg[len],data,n), len += n; free(data); //fprintf(stderr,"send txid.%s\n",txid.GetHex().c_str()); + for (iter=0; iter<3; iter++,sleep(1)); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; isatoshis; utxos[ind] = utxos[--n]; memset(&utxos[n],0,sizeof(utxos[n])); - fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); + //fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break; } From b2bdb24672ae6bc352c9e72445e97a87bea82276 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 00:47:31 -1100 Subject: [PATCH 359/659] Remove sleeps --- src/komodo_nSPV_superlite.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index c1494f721..7cf2c4fca 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -340,7 +340,7 @@ UniValue NSPV_getinfo_req(int32_t reqht) NSPV_inforesp_purge(&NSPV_inforesult); msg[len++] = NSPV_INFO; len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); - for (iter=0; iter<3; iter++,sleep(1)); + for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i Date: Mon, 8 Jul 2019 00:51:47 -1100 Subject: [PATCH 360/659] else sleep(1); --- src/komodo_nSPV_superlite.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 7cf2c4fca..c94513a40 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -349,7 +349,7 @@ UniValue NSPV_getinfo_req(int32_t reqht) if ( NSPV_inforesult.height != 0 ) return(NSPV_getinfo_json(&NSPV_inforesult)); } - } + } else sleep(1); memset(&I,0,sizeof(I)); return(NSPV_getinfo_json(&NSPV_inforesult)); } @@ -378,7 +378,7 @@ UniValue NSPV_addressutxos(char *coinaddr) if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); } - } + } else sleep(1); result.push_back(Pair("result","error")); result.push_back(Pair("error","no utxos result")); return(result); @@ -400,7 +400,7 @@ UniValue NSPV_notarizations(int32_t height) if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) return(NSPV_ntzs_json(&NSPV_ntzsresult)); } - } + } else sleep(1); memset(&N,0,sizeof(N)); return(NSPV_ntzs_json(&N)); } @@ -420,7 +420,7 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) if ( NSPV_ntzsproofresult.prevtxid == prevtxid && NSPV_ntzsproofresult.nexttxid == nexttxid ) return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); } - } + } else sleep(1); memset(&H,0,sizeof(H)); return(NSPV_ntzsproof_json(&H)); } @@ -454,7 +454,7 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) return(NSPV_txproof_json(&NSPV_txproofresult)); } - } + } else sleep(1); //fprintf(stderr,"txproof timeout\n"); memset(&P,0,sizeof(P)); return(NSPV_txproof_json(&P)); @@ -477,7 +477,7 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) return(NSPV_spentinfo_json(&NSPV_spentresult)); } - } + } else sleep(1); memset(&I,0,sizeof(I)); return(NSPV_spentinfo_json(&I)); } @@ -508,7 +508,7 @@ UniValue NSPV_broadcast(char *hex) return(NSPV_broadcast_json(&NSPV_broadcastresult,txid)); } } - } + } else sleep(1); free(msg); memset(&B,0,sizeof(B)); B.retcode = -2; From 79a080292d5d5fb27b42f7d94ff6e95eb64e778a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 00:58:12 -1100 Subject: [PATCH 361/659] Add sleep --- src/komodo_nSPV_wallet.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 557ac3846..4dbcd8f7b 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -162,6 +162,8 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf for (i=0; i 0 ) + sleep(1); validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security From 654b87cef4f54cdd07d43ae9ccda7997b184cc87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 01:11:02 -1100 Subject: [PATCH 362/659] 2 --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 4dbcd8f7b..232ffec8a 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -163,7 +163,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf { utxovout = mtx.vin[i].prevout.n; if ( i > 0 ) - sleep(1); + sleep(2); validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security From b184f1430302620ecab0d5434e89bd71acd9e9b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 01:42:15 -1100 Subject: [PATCH 363/659] Revert --- src/komodo_nSPV.h | 8 +++++++- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4fb2742a6..03c051b2e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -422,7 +422,13 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) int32_t NSPV_pubkeysextract(uint8_t pubkeys[64][33],CTransaction tx,uint8_t elected[64][33]) { - int32_t numsigs = 13; + uint256 hashBlock; CTransaction vintx; int32_t i,numsigs = 13; + /*LOCK(cs_main); + for (i=0; i 0 ) - sleep(2); + sleep(1); validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security From 52445b8430398321ace2a1ddd94ec0246dc7d53b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 02:56:48 -1100 Subject: [PATCH 364/659] Slowflag into CBOPRET if --- src/gtest/test_checktransaction.cpp | 22 +++++++++++----------- src/gtest/test_transaction_builder.cpp | 4 ++-- src/komodo_nSPV.h | 3 --- src/main.cpp | 18 +++++++++--------- src/main.h | 4 ++-- src/test/transaction_tests.cpp | 4 ++-- 6 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/gtest/test_checktransaction.cpp b/src/gtest/test_checktransaction.cpp index c6f66cc64..0efac93db 100644 --- a/src/gtest/test_checktransaction.cpp +++ b/src/gtest/test_checktransaction.cpp @@ -166,7 +166,7 @@ TEST(checktransaction_tests, BadTxnsOversize) { // ... but fails contextual ones! EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-oversize", false)).Times(1); - EXPECT_FALSE(ContextualCheckTransaction(tx, state, 1, 100)); + EXPECT_FALSE(ContextualCheckTransaction(0,tx, state, 1, 100)); } { @@ -188,7 +188,7 @@ TEST(checktransaction_tests, BadTxnsOversize) { MockCValidationState state; EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state)); - EXPECT_TRUE(ContextualCheckTransaction(tx, state, 1, 100)); + EXPECT_TRUE(ContextualCheckTransaction(0,tx, state, 1, 100)); // Revert to default UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT); @@ -508,9 +508,9 @@ TEST(checktransaction_tests, bad_txns_invalid_joinsplit_signature) { MockCValidationState state; // during initial block download, DoS ban score should be zero, else 100 EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1); - ContextualCheckTransaction(tx, state, 0, 100, []() { return true; }); + ContextualCheckTransaction(0,tx, state, 0, 100, []() { return true; }); EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1); - ContextualCheckTransaction(tx, state, 0, 100, []() { return false; }); + ContextualCheckTransaction(0,tx, state, 0, 100, []() { return false; }); } TEST(checktransaction_tests, non_canonical_ed25519_signature) { @@ -522,7 +522,7 @@ TEST(checktransaction_tests, non_canonical_ed25519_signature) { { CTransaction tx(mtx); MockCValidationState state; - EXPECT_TRUE(ContextualCheckTransaction(tx, state, 0, 100)); + EXPECT_TRUE(ContextualCheckTransaction(0,tx, state, 0, 100)); } // Copied from libsodium/crypto_sign/ed25519/ref10/open.c @@ -544,9 +544,9 @@ TEST(checktransaction_tests, non_canonical_ed25519_signature) { MockCValidationState state; // during initial block download, DoS ban score should be zero, else 100 EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1); - ContextualCheckTransaction(tx, state, 0, 100, []() { return true; }); + ContextualCheckTransaction(0,tx, state, 0, 100, []() { return true; }); EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1); - ContextualCheckTransaction(tx, state, 0, 100, []() { return false; }); + ContextualCheckTransaction(0,tx, state, 0, 100, []() { return false; }); } TEST(checktransaction_tests, OverwinterConstructors) { @@ -801,7 +801,7 @@ TEST(checktransaction_tests, OverwinterVersionNumberHigh) { UNSAFE_CTransaction tx(mtx); MockCValidationState state; EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-tx-overwinter-version-too-high", false)).Times(1); - ContextualCheckTransaction(tx, state, 1, 100); + ContextualCheckTransaction(0,tx, state, 1, 100); // Revert to default UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT); @@ -837,9 +837,9 @@ TEST(checktransaction_tests, OverwinterNotActive) { MockCValidationState state; // during initial block download, DoS ban score should be zero, else 100 EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "tx-overwinter-not-active", false)).Times(1); - ContextualCheckTransaction(tx, state, 1, 100, []() { return true; }); + ContextualCheckTransaction(0,tx, state, 1, 100, []() { return true; }); EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "tx-overwinter-not-active", false)).Times(1); - ContextualCheckTransaction(tx, state, 1, 100, []() { return false; }); + ContextualCheckTransaction(0,tx, state, 1, 100, []() { return false; }); } // This tests a transaction without the fOverwintered flag set, against the Overwinter consensus rule set. @@ -856,7 +856,7 @@ TEST(checktransaction_tests, OverwinterFlagNotSet) { CTransaction tx(mtx); MockCValidationState state; EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "tx-overwinter-flag-not-set", false)).Times(1); - ContextualCheckTransaction(tx, state, 1, 100); + ContextualCheckTransaction(0,tx, state, 1, 100); // Revert to default UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT); diff --git a/src/gtest/test_transaction_builder.cpp b/src/gtest/test_transaction_builder.cpp index 05a8cb601..a04e30b0e 100644 --- a/src/gtest/test_transaction_builder.cpp +++ b/src/gtest/test_transaction_builder.cpp @@ -51,7 +51,7 @@ TEST(TransactionBuilder, Invoke) EXPECT_EQ(tx1.valueBalance, -40000); CValidationState state; - EXPECT_TRUE(ContextualCheckTransaction(tx1, state, 2, 0)); + EXPECT_TRUE(ContextualCheckTransaction(0,tx1, state, 2, 0)); EXPECT_EQ(state.GetRejectReason(), ""); // Prepare to spend the note that was just created @@ -85,7 +85,7 @@ TEST(TransactionBuilder, Invoke) EXPECT_EQ(tx2.vShieldedOutput.size(), 2); EXPECT_EQ(tx2.valueBalance, 10000); - EXPECT_TRUE(ContextualCheckTransaction(tx2, state, 3, 0)); + EXPECT_TRUE(ContextualCheckTransaction(0,tx2, state, 3, 0)); EXPECT_EQ(state.GetRejectReason(), ""); // Revert to default diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 03c051b2e..83bb98cf7 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -413,10 +413,7 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) rawdata.resize(datalen); memcpy(&rawdata[0],data,datalen); if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) - { - //fprintf(stderr,"extracted %s\n",tx.GetHash().GetHex().c_str()); return(0); - } else return(-1); } diff --git a/src/main.cpp b/src/main.cpp index 8f54bc71d..8ae2cd47f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1103,7 +1103,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in * Ensure that a coinbase transaction is structured according to the consensus rules of the * chain */ -bool ContextualCheckCoinbaseTransaction(const CBlock *block,CBlockIndex * const previndex,const CTransaction& tx, const int nHeight,int32_t validateprices) +bool ContextualCheckCoinbaseTransaction(int32_t slowflag,const CBlock *block,CBlockIndex * const previndex,const CTransaction& tx, const int nHeight,int32_t validateprices) { // if time locks are on, ensure that this coin base is time locked exactly as it should be if (((uint64_t)(tx.GetValueOut()) >= ASSETCHAINS_TIMELOCKGTE) || @@ -1144,7 +1144,7 @@ bool ContextualCheckCoinbaseTransaction(const CBlock *block,CBlockIndex * const { } - else if ( ASSETCHAINS_CBOPRET != 0 && validateprices != 0 && nHeight > 0 && tx.vout.size() > 0 ) + else if ( slowflag != 0 && ASSETCHAINS_CBOPRET != 0 && validateprices != 0 && nHeight > 0 && tx.vout.size() > 0 ) { if ( komodo_opretvalidate(block,previndex,nHeight,tx.vout[tx.vout.size()-1].scriptPubKey) < 0 ) return(false); @@ -1161,7 +1161,7 @@ bool ContextualCheckCoinbaseTransaction(const CBlock *block,CBlockIndex * const * and ContextualCheckBlock (which calls this function). * 3. The isInitBlockDownload argument is only to assist with testing. */ -bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const previndex, +bool ContextualCheckTransaction(int32_t slowflag,const CBlock *block, CBlockIndex * const previndex, const CTransaction& tx, CValidationState &state, const int nHeight, @@ -1297,7 +1297,7 @@ bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const prevind if (tx.IsCoinBase()) { - if (!ContextualCheckCoinbaseTransaction(block,previndex,tx, nHeight,validateprices)) + if (!ContextualCheckCoinbaseTransaction(slowflag,block,previndex,tx, nHeight,validateprices)) return state.DoS(100, error("CheckTransaction(): invalid script data for coinbase time lock"), REJECT_INVALID, "bad-txns-invalid-script-data-for-coinbase-time-lock"); } @@ -3404,7 +3404,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } if ( fCheckPOW != 0 && (pindex->nStatus & BLOCK_VALID_CONTEXT) != BLOCK_VALID_CONTEXT ) // Activate Jan 15th, 2019 { - if ( !ContextualCheckBlock(block, state, pindex->pprev) ) + if ( !ContextualCheckBlock(1,block, state, pindex->pprev) ) { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); if ( pindex->nTime > 1547510400 ) @@ -5296,7 +5296,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta return true; } -bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIndex * const pindexPrev) +bool ContextualCheckBlock(int32_t slowflag,const CBlock& block, CValidationState& state, CBlockIndex * const pindexPrev) { const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->GetHeight() + 1; const Consensus::Params& consensusParams = Params().GetConsensus(); @@ -5307,7 +5307,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn const CTransaction& tx = block.vtx[i]; // Check transaction contextually against consensus rules at block height - if (!ContextualCheckTransaction(&block,pindexPrev,tx, state, nHeight, 100)) { + if (!ContextualCheckTransaction(slowflag,&block,pindexPrev,tx, state, nHeight, 100)) { return false; // Failure reason has been set in validation state object } @@ -5476,7 +5476,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // See method docstring for why this is always disabled auto verifier = libzcash::ProofVerifier::Disabled(); - bool fContextualCheckBlock = ContextualCheckBlock(block, state, pindex->pprev); + bool fContextualCheckBlock = ContextualCheckBlock(0,block, state, pindex->pprev); if ( (!CheckBlock(futureblockp,pindex->GetHeight(),pindex,block, state, verifier,0)) || !fContextualCheckBlock ) { static int32_t saplinght = -1; @@ -5744,7 +5744,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex //fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW); return false; } - if (!ContextualCheckBlock(block, state, pindexPrev)) + if (!ContextualCheckBlock(0,block, state, pindexPrev)) { //fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW); return false; diff --git a/src/main.h b/src/main.h index d507f9dd6..931954da0 100644 --- a/src/main.h +++ b/src/main.h @@ -706,7 +706,7 @@ bool ContextualCheckInputs(const CTransaction& tx, CValidationState &state, cons std::vector *pvChecks = NULL); /** Check a transaction contextually against a set of consensus rules */ -bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const pindexPrev,const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel, +bool ContextualCheckTransaction(int32_t slowflag,const CBlock *block, CBlockIndex * const pindexPrev,const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel, bool (*isInitBlockDownload)() = IsInitialBlockDownload,int32_t validateprices=1); /** Apply the effects of this transaction on the UTXO set represented by view */ @@ -829,7 +829,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C /** Context-dependent validity checks */ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex *pindexPrev); -bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIndex *pindexPrev); +bool ContextualCheckBlock(int32_t slowflag,const CBlock& block, CValidationState& state, CBlockIndex *pindexPrev); /** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex *pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true); diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index 65524a07e..b6a6ebc26 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -491,7 +491,7 @@ void test_simple_joinsplit_invalidity(uint32_t consensusBranchId, CMutableTransa jsdesc->nullifiers[1] = GetRandHash(); BOOST_CHECK(CheckTransactionWithoutProofVerification(newTx, state)); - BOOST_CHECK(!ContextualCheckTransaction(newTx, state, 0, 100)); + BOOST_CHECK(!ContextualCheckTransaction(0,newTx, state, 0, 100)); BOOST_CHECK(state.GetRejectReason() == "bad-txns-invalid-joinsplit-signature"); // Empty output script. @@ -505,7 +505,7 @@ void test_simple_joinsplit_invalidity(uint32_t consensusBranchId, CMutableTransa ) == 0); BOOST_CHECK(CheckTransactionWithoutProofVerification(newTx, state)); - BOOST_CHECK(ContextualCheckTransaction(newTx, state, 0, 100)); + BOOST_CHECK(ContextualCheckTransaction(0,newTx, state, 0, 100)); } { // Ensure that values within the joinsplit are well-formed. From de0ebde5c3ad94613ab9a60b2b00fb4c35dfddd5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 03:01:50 -1100 Subject: [PATCH 365/659] Syntax --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8ae2cd47f..4c4dbad75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1804,7 +1804,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } // DoS level set to 10 to be more forgiving. // Check transaction contextually against the set of consensus rules which apply in the next block to be mined. - if (!fSkipExpiry && !ContextualCheckTransaction(0,0,tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel,0)) + if (!fSkipExpiry && !ContextualCheckTransaction(0,0,0,tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel,0)) { return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); } From 8441b72f00368b144859e22e578379d818a2cfb7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 03:33:46 -1100 Subject: [PATCH 366/659] Enable notary sig count --- src/komodo_nSPV.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 83bb98cf7..765ca8745 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -417,15 +417,22 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) else return(-1); } -int32_t NSPV_pubkeysextract(uint8_t pubkeys[64][33],CTransaction tx,uint8_t elected[64][33]) +int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { - uint256 hashBlock; CTransaction vintx; int32_t i,numsigs = 13; - /*LOCK(cs_main); + uint8_t scriptPubkey[64]; int32_t i,j,scriptlen,numsigs = 0; for (i=0; i opret; + int32_t numsigs; uint8_t elected[64][33]; char *symbol; std::vector opret; if ( tx.vout.size() >= 2 ) { symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; @@ -453,7 +460,7 @@ int32_t NSPV_notarizationextract(int32_t *ntzheightp,uint256 *blockhashp,uint256 { *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); komodo_notaries(elected,*ntzheightp,0); - if ( (numsigs= NSPV_pubkeysextract(sigkeys,tx,elected)) < 12 ) + if ( (numsigs= NSPV_notariescount(tx,elected)) < 12 ) return(-3); return(0); } else return(-2); From 60005cf28cc59c016fcbe3a4e1f41479279abd09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 03:35:47 -1100 Subject: [PATCH 367/659] Script --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 765ca8745..7218d6c6e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -419,10 +419,10 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { - uint8_t scriptPubkey[64]; int32_t i,j,scriptlen,numsigs = 0; + uint8_t script[64]; int32_t i,j,scriptlen,numsigs = 0; for (i=0; i Date: Mon, 8 Jul 2019 03:37:51 -1100 Subject: [PATCH 368/659] Script --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 7218d6c6e..d8f624a2d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -425,7 +425,7 @@ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) if ( (scriptlen= gettxout_scriptPubKey(script,sizeof(script),tx.vin[i].prevout.hash,tx.vin[i].prevout.n)) == 35 ) { for (j=0; j<64; j++) - if ( memcmp(&scriptPubKey[1],elected[j],33) == 0 ) + if ( memcmp(&script[1],elected[j],33) == 0 ) { numsigs++; break; From 959b2e1484b3461f7a52259e138d4592606963ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 03:43:51 -1100 Subject: [PATCH 369/659] +print --- src/komodo_nSPV_superlite.h | 31 ++++++++++++++++++++++++++++++- src/komodo_nSPV_wallet.h | 25 ------------------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index c94513a40..8a7e9830e 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -37,6 +37,7 @@ struct NSPV_ntzsproofresp NSPV_ntzsproofresult; struct NSPV_txproof NSPV_txproofresult; struct NSPV_broadcastresp NSPV_broadcastresult; + // komodo_nSPVresp is called from async message processing void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response @@ -55,7 +56,11 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r fprintf(stderr,"got old info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status NSPV_inforesp_purge(&NSPV_inforesult); NSPV_inforesult = I; - } // else update headers state + } + else if ( NSPV_inforesult.height > I.height ) + { + NSPV_lastinfo = 0; + } break; case NSPV_UTXOSRESP: NSPV_utxosresp_purge(&NSPV_utxosresult); @@ -133,6 +138,30 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) return(0); } +// komodo_nSPV from main polling loop (really this belongs in its own file, but it is so small, it ended up here) + +void komodo_nSPV(CNode *pto) // polling loop from SendMessages +{ + uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); + if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT ) + NSPV_logout(); + if ( (pto->nServices & NODE_NSPV) == 0 ) + return; + if ( KOMODO_NSPV != 0 ) + { + if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) + { + int32_t reqht; + reqht = 0; + len = 0; + msg[len++] = NSPV_INFO; + len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); + fprintf(stderr,"issue getinfo\n"); + NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); + } + } +} + UniValue NSPV_txproof_json(struct NSPV_txproof *ptr) { UniValue result(UniValue::VOBJ); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 4dbcd8f7b..13339122c 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -291,29 +291,4 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a } } -// polling loop (really this belongs in its own file, but it is so small, it ended up here) - -void komodo_nSPV(CNode *pto) // polling loop from SendMessages -{ - uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); - if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT ) - { - NSPV_logout(); - } - if ( (pto->nServices & NODE_NSPV) == 0 ) - return; - if ( KOMODO_NSPV != 0 ) - { - if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) - { - int32_t reqht; - reqht = 0; - len = 0; - msg[len++] = NSPV_INFO; - len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); - NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); - } - } -} - #endif // KOMODO_NSPVWALLET_H From de22b66bd2a04c64ad1f1523907b5cd7db452b22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 03:46:01 -1100 Subject: [PATCH 370/659] Rearrange --- src/komodo_nSPV_superlite.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 8a7e9830e..efa3f03c1 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -138,6 +138,19 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) return(0); } +UniValue NSPV_logout() +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + if ( NSPV_logintime != 0 ) + fprintf(stderr,"scrub wif and privkey from NSPV memory\n"); + else result.push_back(Pair("status","wasnt logged in")); + memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); + memset(&NSPV_key,0,sizeof(NSPV_key)); + NSPV_logintime = 0; + return(result); +} + // komodo_nSPV from main polling loop (really this belongs in its own file, but it is so small, it ended up here) void komodo_nSPV(CNode *pto) // polling loop from SendMessages @@ -313,19 +326,6 @@ UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid) return(result); } -UniValue NSPV_logout() -{ - UniValue result(UniValue::VOBJ); - result.push_back(Pair("result","success")); - if ( NSPV_logintime != 0 ) - fprintf(stderr,"scrub wif and privkey from NSPV memory\n"); - else result.push_back(Pair("status","wasnt logged in")); - memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); - memset(&NSPV_key,0,sizeof(NSPV_key)); - NSPV_logintime = 0; - return(result); -} - UniValue NSPV_login(char *wifstr) { UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0; From d6883ab589760cafa897fb2c604050321ed19a67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 04:12:07 -1100 Subject: [PATCH 371/659] +print --- src/komodo_nSPV.h | 4 ++-- src/komodo_nSPV_superlite.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d8f624a2d..8d717ec98 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -430,9 +430,9 @@ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) numsigs++; break; } - } + } else fprintf(stderr,"invalid scriptlen.%d\n",scriptlen); } - fprintf(stderr,"numsigs.%d\n",numsigs); + fprintf(stderr,"numvins.%d numsigs.%d\n",(int32_t)tx.vin.size(),numsigs); return(numsigs); } diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index efa3f03c1..5a0e152fd 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -169,7 +169,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages len = 0; msg[len++] = NSPV_INFO; len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); - fprintf(stderr,"issue getinfo\n"); + //fprintf(stderr,"issue getinfo\n"); NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); } } @@ -616,7 +616,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int } } } else retval = -22; - } else retval = -2; + } else retval = -24; } return(retval); } From 496efd01624ba8757d99861d628ffe5f17d25afd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 04:58:56 -1100 Subject: [PATCH 372/659] Remote get --- src/komodo_nSPV.h | 32 ++++++++++++++++++++------------ src/komodo_nSPV_fullnode.h | 5 ++--- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 8d717ec98..9691b0eb8 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -50,6 +50,8 @@ #define NSPV_BROADCAST 0x0c #define NSPV_BROADCASTRESP 0x0d +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx); + int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf) { if ( rwflag != 0 ) @@ -419,21 +421,27 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { - uint8_t script[64]; int32_t i,j,scriptlen,numsigs = 0; + uint8_t *script[64]; int32_t i,j,utxovout,scriptlen,numsigs = 0; for (i=0; i opret,uint256 txid) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index e71d47d07..396fa1105 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -227,7 +227,7 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 ptr->txid = txid; ptr->vout = vout; ptr->height = height; - if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) + if ( height != 0 && (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) { BOOST_FOREACH(const CTransaction&tx, block.vtx) { @@ -254,10 +254,9 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 } ptr->unspentvalue = CCgettxout(txid,vout,1,1); //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); - return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); } } - return(-1); + return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); } int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid,uint256 nextntztxid) From 7e4c4146e6f2c3ba5c022c0645cdf709b007f6a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 05:02:01 -1100 Subject: [PATCH 373/659] Fix --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9691b0eb8..0ea5ddf19 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -421,7 +421,7 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { - uint8_t *script[64]; int32_t i,j,utxovout,scriptlen,numsigs = 0; + uint8_t *script[64]; CTransaction vintx; int32_t i,j,utxovout,scriptlen,numsigs = 0; for (i=0; i Date: Mon, 8 Jul 2019 05:04:22 -1100 Subject: [PATCH 374/659] Syntax --- src/komodo_nSPV.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 0ea5ddf19..becd08015 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -421,7 +421,7 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { - uint8_t *script[64]; CTransaction vintx; int32_t i,j,utxovout,scriptlen,numsigs = 0; + uint8_t *script; CTransaction vintx; int32_t i,j,utxovout,scriptlen,numsigs = 0; for (i=0; i opret,uint256 txid) From 28d438336ed04a3f773a4e4457df7168e30b1342 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 05:06:40 -1100 Subject: [PATCH 375/659] Utxovout --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index becd08015..10a2abecf 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -430,7 +430,7 @@ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) if ( utxovout < vintx.vout.size() ) { script = (uint8_t *)&vintx.vout[utxovout].scriptPubKey[0]; - if ( (scriptlen= vintx.vout[n].scriptPubKey.size()) == 35 ) + if ( (scriptlen= vintx.vout[utxovout].scriptPubKey.size()) == 35 ) { for (j=0; j<64; j++) if ( memcmp(&script[1],elected[j],33) == 0 ) From 0219ccbe6f04844b3fcbdde5eadb1b8e59f0f0ab Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 05:25:52 -1100 Subject: [PATCH 376/659] +prints --- src/komodo_nSPV.h | 9 ++++++--- src/komodo_nSPV_fullnode.h | 4 ++-- src/komodo_nSPV_superlite.h | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 10a2abecf..fabfef560 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -426,7 +426,10 @@ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { utxovout = tx.vin[i].prevout.n; if ( NSPV_gettransaction(1,utxovout,tx.vin[i].prevout.hash,0,tx) != 0 ) + { + fprintf(stderr,"error getting %s/v%d\n",tx.vin[i].prevout.hash.GetHex().c_str(),utxovout); return(numsigs); + } if ( utxovout < vintx.vout.size() ) { script = (uint8_t *)&vintx.vout[utxovout].scriptPubKey[0]; @@ -439,7 +442,7 @@ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) break; } } else fprintf(stderr,"invalid scriptlen.%d\n",scriptlen); - } + } else fprintf(stderr,"invalid utxovout.%d vs %d\n",utxovout,(int32_t)vintx.vout.size()); } fprintf(stderr,"numvins.%d numsigs.%d\n",(int32_t)tx.vin.size(),numsigs); return(numsigs); @@ -458,7 +461,7 @@ uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std: return(desttxid); } -int32_t NSPV_notarizationextract(int32_t *ntzheightp,uint256 *blockhashp,uint256 *desttxidp,CTransaction tx) +int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 *blockhashp,uint256 *desttxidp,CTransaction tx) { int32_t numsigs; uint8_t elected[64][33]; char *symbol; std::vector opret; if ( tx.vout.size() >= 2 ) @@ -469,7 +472,7 @@ int32_t NSPV_notarizationextract(int32_t *ntzheightp,uint256 *blockhashp,uint256 { *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); komodo_notaries(elected,*ntzheightp,0); - if ( (numsigs= NSPV_notariescount(tx,elected)) < 12 ) + if ( verifyntz != 0 && (numsigs= NSPV_notariescount(tx,elected)) < 12 ) return(-3); return(0); } else return(-2); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 396fa1105..ff78948f6 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -265,7 +265,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid ptr->prevtxid = prevntztxid; ptr->prevntz = NSPV_getrawtx(tx,hashBlock,&ptr->prevtxlen,ptr->prevtxid); ptr->prevtxidht = komodo_blockheight(hashBlock); - if ( NSPV_notarizationextract(&ptr->common.prevht,&bhash0,&desttxid0,tx) < 0 ) + if ( NSPV_notarizationextract(0,&ptr->common.prevht,&bhash0,&desttxid0,tx) < 0 ) return(-2); else if ( komodo_blockheight(bhash0) != ptr->common.prevht ) return(-3); @@ -273,7 +273,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid ptr->nexttxid = nextntztxid; ptr->nextntz = NSPV_getrawtx(tx,hashBlock,&ptr->nexttxlen,ptr->nexttxid); ptr->nexttxidht = komodo_blockheight(hashBlock); - if ( NSPV_notarizationextract(&ptr->common.nextht,&bhash1,&desttxid1,tx) < 0 ) + if ( NSPV_notarizationextract(0,&ptr->common.nextht,&bhash1,&desttxid1,tx) < 0 ) return(-5); else if ( komodo_blockheight(bhash1) != ptr->common.nextht ) return(-6); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5a0e152fd..eb42bedd8 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -553,7 +553,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-2); else if ( tx.GetHash() != ptr->nexttxid ) return(-3); - else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 ) + else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) return(-4); else if ( height != ptr->common.nextht ) return(-5); @@ -569,7 +569,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(-7); else if ( tx.GetHash() != ptr->prevtxid ) return(-8); - else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 ) + else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) return(-9); else if ( height != ptr->common.prevht ) return(-10); From 2e56335f4332d2993ae7589a4959a0e5be40b9f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 05:32:11 -1100 Subject: [PATCH 377/659] +prints --- src/komodo_nSPV.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fabfef560..87110ff5d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -463,19 +463,28 @@ uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std: int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 *blockhashp,uint256 *desttxidp,CTransaction tx) { - int32_t numsigs; uint8_t elected[64][33]; char *symbol; std::vector opret; + int32_t numsigs=0; uint8_t elected[64][33]; char *symbol; std::vector opret; + fprintf(stderr,"ntz vouts[%d]\n",(int32_t)tx.vout.size()); if ( tx.vout.size() >= 2 ) { symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; GetOpReturnData(tx.vout[1].scriptPubKey,opret); - if ( opret.size() >= 32*2+4*2 ) + if ( opret.size() >= 32*2+4 ) { *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); komodo_notaries(elected,*ntzheightp,0); if ( verifyntz != 0 && (numsigs= NSPV_notariescount(tx,elected)) < 12 ) + { + fprintf(stderr,"numsigs.%d error\n",numsigs); return(-3); + } return(0); - } else return(-2); + } + else + { + fprintf(stderr,"opretsize.%d error\n",(int32_t)opret.size()); + return(-2); + } } else return(-1); } #endif // KOMODO_NSPV_H From 33e1c2f08fa54ed96f75d73c6bacddb852b0d200 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 05:38:26 -1100 Subject: [PATCH 378/659] Set unspentvalue for ht.0 req --- src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_superlite.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index ff78948f6..7d74dbcf2 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -252,10 +252,10 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); memcpy(ptr->txproof,&proof[0],ptr->txprooflen); } - ptr->unspentvalue = CCgettxout(txid,vout,1,1); //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); } } + ptr->unspentvalue = CCgettxout(txid,vout,1,1); return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); } diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index eb42bedd8..5d400def1 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -583,7 +583,10 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int int32_t offset,retval = 0; NSPV_txproof(vout,txid,height); if ( NSPV_txproofresult.txid != txid || NSPV_txproofresult.unspentvalue <= 0 ) + { + fprintf(stderr,"txproof error value %.8f\n",(double)NSPV_txproofresult.unspentvalue/COIN); return(-1); + } else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) retval = -20; else if ( skipvalidation == 0 ) From 9c9bf90c45c99bb8874af37a04bf3fdd865f070c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 05:52:15 -1100 Subject: [PATCH 379/659] Test --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 87110ff5d..4cc84729b 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -425,6 +425,7 @@ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) for (i=0; i Date: Mon, 8 Jul 2019 06:03:51 -1100 Subject: [PATCH 380/659] Test --- src/komodo_nSPV_superlite.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5d400def1..334df4489 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -582,13 +582,15 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int { int32_t offset,retval = 0; NSPV_txproof(vout,txid,height); - if ( NSPV_txproofresult.txid != txid || NSPV_txproofresult.unspentvalue <= 0 ) + if ( NSPV_txproofresult.txid != txid ) { fprintf(stderr,"txproof error value %.8f\n",(double)NSPV_txproofresult.unspentvalue/COIN); return(-1); } else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) retval = -20; + else if ( skipvalidation == 0 && NSPV_txproofresult.unspentvalue <= 0 ) + retval = -21; else if ( skipvalidation == 0 ) { NSPV_notarizations(height); // gets the prev and next notarizations From f15cdae1854d74b8f61973a24a8cfecf82abdd0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:17:14 -1100 Subject: [PATCH 381/659] Use vintx! --- src/komodo_nSPV.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4cc84729b..921879730 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -419,14 +419,21 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) else return(-1); } +/* + NSPV_notariescount is the slowest process during full validation as it requires looking up 13 transactions. + one way that would be 10000x faster would be to bruteforce validate the signatures in each vin, against all 64 pubkeys! for a valid tx, that is on average 13*32 secp256k1/sapling verify operations, which is much faster than even a single network request. + Unfortunately, due to the complexity of calculating the hash to sign for a tx, this bruteforcing would require determining what type of signature method and having sapling vs legacy methods of calculating the txhash. + It could be that the fullnode side could calculate this and send it back to the superlite side as any hash that would validate 13 different ways has to be the valid txhash. + However, since the vouts being spent by the notaries are highly constrained p2pk vouts, the txhash can be deduced if a specific notary pubkey is indeed the signer + */ + int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { uint8_t *script; CTransaction vintx; int32_t i,j,utxovout,scriptlen,numsigs = 0; for (i=0; i opret; - fprintf(stderr,"ntz vouts[%d]\n",(int32_t)tx.vout.size()); if ( tx.vout.size() >= 2 ) { symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; From 86fe5d41d927ad164c9601fc74ed56d541b992e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:24:32 -1100 Subject: [PATCH 382/659] +print --- src/komodo_nSPV_superlite.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 334df4489..8bf7d289d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -48,6 +48,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r switch ( response[0] ) { case NSPV_INFORESP: + fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status I = NSPV_inforesult; NSPV_inforesp_purge(&NSPV_inforesult); NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); From ea2fd93812937577c3394ce0a5250c1db5005f28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:25:15 -1100 Subject: [PATCH 383/659] +print --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 8bf7d289d..328924ef3 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -170,7 +170,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages len = 0; msg[len++] = NSPV_INFO; len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); - //fprintf(stderr,"issue getinfo\n"); + fprintf(stderr,"issue getinfo\n"); NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); } } From b3462d0342404252c06266997e9d14db77415d95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:28:51 -1100 Subject: [PATCH 384/659] Autoclear bad timestamp --- src/komodo_nSPV_superlite.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 328924ef3..c1af16bfc 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -161,6 +161,8 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages NSPV_logout(); if ( (pto->nServices & NODE_NSPV) == 0 ) return; + if ( pto->prevtimes[NSPV_INFO>>1] > timestamp ) + pto->prevtimes[NSPV_INFO>>1] = 0; if ( KOMODO_NSPV != 0 ) { if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) From e324c8b063b8f029f6cf3a135389ef69bcca4c8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:34:10 -1100 Subject: [PATCH 385/659] .GetHex().c_str() --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index c1af16bfc..35b16182b 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -48,7 +48,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r switch ( response[0] ) { case NSPV_INFORESP: - fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status + //fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status I = NSPV_inforesult; NSPV_inforesp_purge(&NSPV_inforesult); NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); @@ -172,7 +172,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages len = 0; msg[len++] = NSPV_INFO; len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); - fprintf(stderr,"issue getinfo\n"); + //fprintf(stderr,"issue getinfo\n"); NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); } } @@ -587,7 +587,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int NSPV_txproof(vout,txid,height); if ( NSPV_txproofresult.txid != txid ) { - fprintf(stderr,"txproof error value %.8f\n",(double)NSPV_txproofresult.unspentvalue/COIN); + fprintf(stderr,"txproof error %s != %s\n",NSPV_txproofresult.txid.GetHex().c_str(),txid.GetHex().c_str()); return(-1); } else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) From 6b78dde414a7d054996ca648b96142ee0f4ecf05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:39:45 -1100 Subject: [PATCH 386/659] Allow ht.0 in taproot --- src/komodo_nSPV_superlite.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 35b16182b..910d3ef84 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -59,9 +59,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r NSPV_inforesult = I; } else if ( NSPV_inforesult.height > I.height ) - { - NSPV_lastinfo = 0; - } + NSPV_lastinfo = timestamp - ASSETCHAINS_BLOCKTIME/4; break; case NSPV_UTXOSRESP: NSPV_utxosresp_purge(&NSPV_utxosresult); @@ -476,14 +474,14 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); - //fprintf(stderr,"req txproof %s/v%d at height.%d\n",txid.GetHex().c_str(),vout,height); + fprintf(stderr,"req txproof %s/v%d at height.%d\n",txid.GetHex().c_str(),vout,height); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i Date: Mon, 8 Jul 2019 06:41:19 -1100 Subject: [PATCH 387/659] Speedup listunspent --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 910d3ef84..3c306aba5 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -405,7 +405,7 @@ UniValue NSPV_addressutxos(char *coinaddr) for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 ) + if ( strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); } } else sleep(1); From f94ed2c3b3a6d877d9a669dfdf346309c1b01968 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:43:51 -1100 Subject: [PATCH 388/659] Speedup --- src/komodo_nSPV.h | 4 ++-- src/komodo_nSPV_fullnode.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 921879730..9029318a0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -27,8 +27,8 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_POLLITERS 15 -#define NSPV_POLLMICROS 100000 +#define NSPV_POLLITERS 10 +#define NSPV_POLLMICROS 100777 #define NSPV_MAXVINS 64 #define NSPV_AUTOLOGOUT 777 #define NSPV_BRANCHID 0x76b809bb diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 7d74dbcf2..2795e1c65 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -145,7 +145,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); - if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 && ptr->numutxos < maxlen ) + if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) >= 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); ptr->nodeheight = tipheight; From ee5e804292cf544f9b2e9ef9cd6b5800c300ccc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:45:27 -1100 Subject: [PATCH 389/659] Test for timeout --- src/komodo_nSPV_superlite.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 3c306aba5..f1d68002d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -405,7 +405,7 @@ UniValue NSPV_addressutxos(char *coinaddr) for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); } } else sleep(1); @@ -582,7 +582,13 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx) { int32_t i,offset,retval = 0; - NSPV_txproof(vout,txid,height); + for (i=0; i<3; i++) + { + NSPV_txproof(vout,txid,height); + if ( NSPV_txproofresult.txlen != 0 ) + break; + sleep(1); + } if ( NSPV_txproofresult.txid != txid ) { fprintf(stderr,"txproof error %s != %s\n",NSPV_txproofresult.txid.GetHex().c_str(),txid.GetHex().c_str()); From c35927ae31a01a49ba1c52f49eebfddc45debbf2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:51:04 -1100 Subject: [PATCH 390/659] Purge all global requests on issuing --- src/komodo_nSPV_superlite.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index f1d68002d..ff1fc7a30 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -388,6 +388,7 @@ UniValue NSPV_addressutxos(char *coinaddr) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); + NSPV_utxosresp_purge(&NSPV_utxosresult); if ( bitcoin_base58decode(msg,coinaddr) != 25 ) { result.push_back(Pair("result","error")); @@ -419,6 +420,7 @@ UniValue NSPV_notarizations(int32_t height) uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N; //if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) // return(NSPV_ntzs_json(&NSPV_ntzsresult)); + NSPV_ntzsresp_purge(&NSPV_ntzsresult); msg[len++] = NSPV_NTZS; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); for (iter=0; iter<3; iter++); @@ -438,6 +440,7 @@ UniValue NSPV_notarizations(int32_t height) UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsproofresp H; + NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid); @@ -470,6 +473,7 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_txproof P; //if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) // return(NSPV_txproof_json(&NSPV_txproofresult)); + NSPV_txproof_purge(&NSPV_txproofresult); msg[len++] = NSPV_TXPROOF; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); @@ -495,6 +499,7 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_spentinfo I; //if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) // return(NSPV_spentinfo_json(&NSPV_spentresult)); + NSPV_spentinfo_purge(&NSPV_spentinforesult); msg[len++] = NSPV_SPENTINFO; len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); @@ -515,6 +520,7 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) UniValue NSPV_broadcast(char *hex) { uint8_t *msg,*data; uint256 txid; uint16_t n; int32_t i,iter,len = 0; struct NSPV_broadcastresp B; + NSPV_broadcast_purge(&NSPV_broadcastresult); n = (int32_t)strlen(hex) >> 1; data = (uint8_t *)malloc(n); decode_hex(data,n,hex); From 927aca6f01faf5ca953129d376141bcc3b5a6522 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 06:53:01 -1100 Subject: [PATCH 391/659] Spent result --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index ff1fc7a30..feab3859c 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -499,7 +499,7 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_spentinfo I; //if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) // return(NSPV_spentinfo_json(&NSPV_spentresult)); - NSPV_spentinfo_purge(&NSPV_spentinforesult); + NSPV_spentinfo_purge(&NSPV_spentresult); msg[len++] = NSPV_SPENTINFO; len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); From b069d6a74a703778435c0bdcd3402f6761e980b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 07:03:35 -1100 Subject: [PATCH 392/659] Grab proof before overwritten --- src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_superlite.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 2795e1c65..494c511e1 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -167,7 +167,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check if ( len < maxlen ) { len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos - sizeof(ptr->utxos)); - fprintf(stderr,"getaddressutxos for %s -> n.%d:%d total %.8f interest %.8f len.%d\n",coinaddr,n,ptr->numutxos,dstr(total),dstr(interest),len); + //fprintf(stderr,"getaddressutxos for %s -> n.%d:%d total %.8f interest %.8f len.%d\n",coinaddr,n,ptr->numutxos,dstr(total),dstr(interest),len); if ( n == ptr->numutxos ) { ptr->total = total; diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index feab3859c..ef67d86d9 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -587,7 +587,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx) { - int32_t i,offset,retval = 0; + int32_t i,offset,retval = 0; std::vector proof; for (i=0; i<3; i++) { NSPV_txproof(vout,txid,height); @@ -606,6 +606,11 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int retval = -21; else if ( skipvalidation == 0 ) { + if ( NSPV_txproofresult.txprooflen > 0 ) + { + proof.resize(NSPV_txproofresult.txprooflen); + memcpy(&proof[0],NSPV_txproofresult.txproof,txprooflen); + } NSPV_notarizations(height); // gets the prev and next notarizations if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) { @@ -623,9 +628,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { - std::vector txids; std::vector proof; uint256 proofroot; - proof.resize(NSPV_txproofresult.txprooflen); - memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); + std::vector txids; uint256 proofroot; proofroot = BitcoinGetProofMerkleRoot(proof,txids); if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) { From b46f0079d93c5b45b1e2bd3543f19ef2269ee634 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 07:08:55 -1100 Subject: [PATCH 393/659] NSPV_txproofresult. --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_superlite.h | 5 +++-- src/komodo_nSPV_wallet.h | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9029318a0..a5de92f4d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -27,6 +27,7 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H +#define NSPV_FULLVALIDATION 1 // changing to 1 issues 26 remote gettransaction, per utxo! need to change to bruteforcer #define NSPV_POLLITERS 10 #define NSPV_POLLMICROS 100777 #define NSPV_MAXVINS 64 diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index ef67d86d9..43112ed70 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -478,7 +478,7 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); - fprintf(stderr,"req txproof %s/v%d at height.%d\n",txid.GetHex().c_str(),vout,height); + //fprintf(stderr,"req txproof %s/v%d at height.%d\n",txid.GetHex().c_str(),vout,height); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { @@ -609,7 +609,8 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int if ( NSPV_txproofresult.txprooflen > 0 ) { proof.resize(NSPV_txproofresult.txprooflen); - memcpy(&proof[0],NSPV_txproofresult.txproof,txprooflen); + memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); + fprintf(stderr,"copy txproof[%d]\n",txprooflen); } NSPV_notarizations(height); // gets the prev and next notarizations if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 13339122c..d0d079e61 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -164,7 +164,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf utxovout = mtx.vin[i].prevout.n; if ( i > 0 ) sleep(1); - validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); + validation = NSPV_gettransaction(NSPV_FULLVALIDATION,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security { From 3064ea35789e6b969627e6d49488584a9a5e7459 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 07:10:03 -1100 Subject: [PATCH 394/659] -print --- src/komodo_nSPV_superlite.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 43112ed70..2b7f5b688 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -610,7 +610,6 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int { proof.resize(NSPV_txproofresult.txprooflen); memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); - fprintf(stderr,"copy txproof[%d]\n",txprooflen); } NSPV_notarizations(height); // gets the prev and next notarizations if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) From f02128fb82fd5629fd713265ccc1e73ce911c344 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 07:13:44 -1100 Subject: [PATCH 395/659] Test --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a5de92f4d..a84d48ac2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -27,7 +27,7 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_FULLVALIDATION 1 // changing to 1 issues 26 remote gettransaction, per utxo! need to change to bruteforcer +#define NSPV_SKIPFULLVALIDATION 0 // changing to 0 issues 26 remote gettransaction, per utxo! need to change to bruteforcer #define NSPV_POLLITERS 10 #define NSPV_POLLMICROS 100777 #define NSPV_MAXVINS 64 diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index d0d079e61..f04cef11b 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -164,7 +164,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf utxovout = mtx.vin[i].prevout.n; if ( i > 0 ) sleep(1); - validation = NSPV_gettransaction(NSPV_FULLVALIDATION,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); + validation = NSPV_gettransaction(NSPV_SKIPFULLVALIDATION,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security { From 5685c7f49c2abfc1ec3f486ca4c746eafca98b22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 07:18:24 -1100 Subject: [PATCH 396/659] Disable full validation --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a84d48ac2..ba59252cc 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -27,7 +27,7 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_SKIPFULLVALIDATION 0 // changing to 0 issues 26 remote gettransaction, per utxo! need to change to bruteforcer +#define NSPV_SKIPFULLVALIDATION 1 // changing to 0 issues 26 remote gettransaction, per utxo! need to change to bruteforcer #define NSPV_POLLITERS 10 #define NSPV_POLLMICROS 100777 #define NSPV_MAXVINS 64 From 19f55b42ab08df53078610c616bf5a740b81add4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 07:27:52 -1100 Subject: [PATCH 397/659] Error code separation --- src/komodo_nSPV.h | 5 ++--- src/komodo_nSPV_superlite.h | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index ba59252cc..b7b38cf57 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -16,11 +16,10 @@ // todo: -// pubkeys extract -// headers "sync" +// headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs + // interest calculations are currently just using what is returned, it should calculate it from scratch -// need to validate incoming data and update only if it is valid and more recent // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 2b7f5b688..813390c01 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -601,9 +601,9 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int return(-1); } else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) - retval = -20; + retval = -2000; else if ( skipvalidation == 0 && NSPV_txproofresult.unspentvalue <= 0 ) - retval = -21; + retval = -2001; else if ( skipvalidation == 0 ) { if ( NSPV_txproofresult.txprooflen > 0 ) @@ -633,11 +633,11 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) { fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",NSPV_txproofresult.txprooflen,proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); - retval = -23; + retval = -2003; } } - } else retval = -22; - } else retval = -24; + } else retval = -2002; + } else retval = -2004; } return(retval); } From 2d259720080d18d50c69b5f05d33529156148b55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 17:52:51 -1100 Subject: [PATCH 398/659] +comments --- src/komodo_nSPV.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b7b38cf57..cba34c290 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -20,6 +20,8 @@ // interest calculations are currently just using what is returned, it should calculate it from scratch +// bruteforce sig -> NN pubkey validator +// CC signing // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) From 9c366e56e8f13ccb0e15c96f1fd18c9ee256c351 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 18:56:50 -1100 Subject: [PATCH 399/659] New field --- src/komodo_nSPV_superlite.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 813390c01..d23c35363 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -235,6 +235,7 @@ UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr) { UniValue result(UniValue::VOBJ); int32_t expiration; uint32_t timestamp = (uint32_t)time(NULL); result.push_back(Pair("result","success")); + result.push_back(Pair("nSPV",KOMODO_NSPV!=0?"superlite":"fullnode")); if ( NSPV_address.size() != 0 ) { result.push_back(Pair("address",NSPV_address)); From 23df289f70236cdeabca5adee79553cb86b64450 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 19:35:45 -1100 Subject: [PATCH 400/659] CC address support for nspv_listunspent --- src/komodo_nSPV_fullnode.h | 10 +++++++--- src/komodo_nSPV_superlite.h | 4 ++-- src/wallet/rpcdump.cpp | 21 +++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 494c511e1..f8cc47925 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -137,7 +137,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) } else return(-1); } -int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check mempool +int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC) // check mempool { int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; std::vector > unspentOutputs; @@ -362,12 +362,16 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_utxosresp U; char coinaddr[64]; - if ( len < 64 && request[1] == len-2 ) + if ( len < 64 && (request[1] == len-2 || request[1] == len-3) ) { + uint8_t isCC = 0; memcpy(coinaddr,&request[2],request[1]); coinaddr[request[1]] = 0; + if ( request[1] == len-3 ) + isCC = (request[len-1] != 0); + fprintf(stderr,"isCC.%d\n",isCC); memset(&U,0,sizeof(U)); - if ( (slen= NSPV_getaddressutxos(&U,coinaddr)) > 0 ) + if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d23c35363..150d0859c 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -385,7 +385,7 @@ UniValue NSPV_getinfo_req(int32_t reqht) return(NSPV_getinfo_json(&NSPV_inforesult)); } -UniValue NSPV_addressutxos(char *coinaddr) +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); @@ -400,7 +400,7 @@ UniValue NSPV_addressutxos(char *coinaddr) msg[len++] = NSPV_UTXOS; msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; - msg[len] = 0; + msg[len++] = (CCflag != 0); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index b197b73b0..82e44190c 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -975,7 +975,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) UniValue NSPV_getinfo_req(int32_t reqht); UniValue NSPV_login(char *wifstr); UniValue NSPV_logout(); -UniValue NSPV_addressutxos(char *coinaddr); +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag); UniValue NSPV_broadcast(char *hex); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); @@ -1011,17 +1011,22 @@ UniValue nspv_login(const UniValue& params, bool fHelp) UniValue nspv_listunspent(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() > 1 ) - throw runtime_error("nspv_listunspent address\n"); + int32_t CCflag = 0; + if ( fHelp || params.size() > 2 ) + throw runtime_error("nspv_listunspent address [isCC]\n"); if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) - return(NSPV_addressutxos((char *)NSPV_address.c_str())); - else throw runtime_error("nspv_listunspent address\n"); + return(NSPV_addressutxos((char *)NSPV_address.c_str(),0)); + else throw runtime_error("nspv_listunspent address [isCC]\n"); } - if ( params.size() == 1 ) - return(NSPV_addressutxos((char *)params[0].get_str().c_str())); - else throw runtime_error("nspv_listunspent address\n"); + if ( params.size() >= 1 ) + { + if ( params.size() == 2 ) + CCflag = atoi((char *)params[1].get_str().c_str()); + return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag)); + } + else throw runtime_error("nspv_listunspent address [isCC]\n"); } UniValue nspv_spentinfo(const UniValue& params, bool fHelp) From b9cb5e7b4be3ac6573cd90f4a6c185f9bdf17bfe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 19:39:49 -1100 Subject: [PATCH 401/659] Full CCflag support --- src/komodo_nSPV.h | 5 +++-- src/komodo_nSPV_fullnode.h | 1 + src/komodo_nSPV_superlite.h | 1 + src/komodo_nSPV_wallet.h | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index cba34c290..77c352659 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -140,7 +140,7 @@ struct NSPV_utxosresp char coinaddr[64]; int64_t total,interest; int32_t nodeheight; - uint16_t numutxos,pad16; + uint16_t numutxos; uint8_t CCflag,pad8; }; int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosresp *ptr) // check mempool @@ -157,7 +157,8 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->total),&ptr->total); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad8),&ptr->pad8); if ( rwflag != 0 ) { memcpy(&serialized[len],ptr->coinaddr,sizeof(ptr->coinaddr)); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index f8cc47925..c28c247cb 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -145,6 +145,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); + ptr->CCflag = isCC; if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) >= 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 150d0859c..3f11ab74f 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -276,6 +276,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) result.push_back(Pair("result","success")); result.push_back(Pair("utxos",NSPV_utxoresp_json(ptr->utxos,ptr->numutxos))); result.push_back(Pair("address",ptr->coinaddr)); + result.push_back(Pair("isCC",ptr->CCflag)); result.push_back(Pair("height",(int64_t)ptr->nodeheight)); result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); result.push_back(Pair("balance",(double)ptr->total/COIN)); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index f04cef11b..397dbe625 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -218,7 +218,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) - NSPV_addressutxos(srcaddr); + NSPV_addressutxos(srcaddr,0); if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { result.push_back(Pair("result","error")); From 80d02fbb42ff45e6bda718e9dd4d67f19b22ca56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:05:51 -1100 Subject: [PATCH 402/659] Query CC --- src/komodo_nSPV_fullnode.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index c28c247cb..cdfb0f57e 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -141,7 +141,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC { int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; std::vector > unspentOutputs; - SetCCunspents(unspentOutputs,coinaddr,false); + SetCCunspents(unspentOutputs,coinaddr,isCC); maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); @@ -370,7 +370,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req coinaddr[request[1]] = 0; if ( request[1] == len-3 ) isCC = (request[len-1] != 0); - fprintf(stderr,"isCC.%d\n",isCC); + if ( isCC != 0 ) + fprintf(stderr,"%s isCC.%d\n",coinaddr,isCC); memset(&U,0,sizeof(U)); if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC)) > 0 ) { From c9a6b6218a3878d6053c3eee190aeda470e51250 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:16:57 -1100 Subject: [PATCH 403/659] +print --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_wallet.h | 3 ++- src/script/sign.cpp | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 77c352659..72a23d23f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -53,6 +53,7 @@ #define NSPV_BROADCASTRESP 0x0d int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx); +extern uint256 SIG_TXHASH; int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf) { diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 397dbe625..a53ec77b2 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -135,8 +135,9 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) { UpdateTransaction(mtx,vini,sigdata); + fprintf(stderr,"SIGTXHASH %s vini.%d %.8f\n",SIGTXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); - } // else fprintf(stderr,"signing error for SignTx vini.%d %.8f\n",vini,(double)utxovalue/COIN); + } else fprintf(stderr,"sigerr SIGTXHASH %s vini.%d %.8f\n",SIGTXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); } diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 685018828..1865d8e35 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -35,6 +35,7 @@ using namespace std; typedef vector valtype; extern uint8_t ASSETCHAINS_TXPOW; +uint256 SIG_TXHASH; TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} @@ -52,7 +53,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } catch (logic_error ex) { return false; } - + TXHASH = hash; if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; From 80377ebdc938d49d2f9a4dfd8fe6e70471b73d88 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:18:03 -1100 Subject: [PATCH 404/659] SIG_TXHASH --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index a53ec77b2..4ab094562 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -135,9 +135,9 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) { UpdateTransaction(mtx,vini,sigdata); - fprintf(stderr,"SIGTXHASH %s vini.%d %.8f\n",SIGTXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); - } else fprintf(stderr,"sigerr SIGTXHASH %s vini.%d %.8f\n",SIGTXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + } else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); } From cdfcb27820cc9838a9f881a575204744d9b516bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:20:45 -1100 Subject: [PATCH 405/659] SIG_TXHASH --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 1865d8e35..71fa4cee4 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -53,7 +53,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } catch (logic_error ex) { return false; } - TXHASH = hash; + SIG_TXHASH = hash; if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; From c466bfd18a398d8d22b0146c9bcf02a2ab5663de Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:38:18 -1100 Subject: [PATCH 406/659] New notaries count --- src/komodo_nSPV.h | 23 ++++++++++++++++++++++- src/komodo_nSPV_superlite.h | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 72a23d23f..614e7f86f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -431,6 +431,27 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) However, since the vouts being spent by the notaries are highly constrained p2pk vouts, the txhash can be deduced if a specific notary pubkey is indeed the signer */ +bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); + +int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) +{ + CPubKey pubkeys[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + for (j=0; j<64; j++) + { + pubkeys[j] = buf2pk(elected[j]); + scriptPubKeys[j] = CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); + } + for (vini=0; vini= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 ) + if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); } } else sleep(1); From ccae5863fa178183089e34e1aceda0c637bec7e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:40:22 -1100 Subject: [PATCH 407/659] Flag --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 614e7f86f..67476f105 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -28,7 +28,7 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_SKIPFULLVALIDATION 1 // changing to 0 issues 26 remote gettransaction, per utxo! need to change to bruteforcer +#define NSPV_SKIPFULLVALIDATION 0 // changing to 0 issues 26 remote gettx, per utxo! need local bruteforcer #define NSPV_POLLITERS 10 #define NSPV_POLLMICROS 100777 #define NSPV_MAXVINS 64 @@ -439,7 +439,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); - scriptPubKeys[j] = CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); + scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); } for (vini=0; vini Date: Mon, 8 Jul 2019 20:45:23 -1100 Subject: [PATCH 408/659] NSPV_utxosresult.CCflag != 0 || --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 4ab094562..0a8ca30d2 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -218,9 +218,9 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a result.push_back(Pair("error","couldnt getinfo")); return(result); } - if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) + if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) NSPV_addressutxos(srcaddr,0); - if ( strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) + if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { result.push_back(Pair("result","error")); result.push_back(Pair("address",NSPV_utxosresult.coinaddr)); From 492dc5c2cc5e92048b4fc22b4d8ecd76c631a9f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:49:12 -1100 Subject: [PATCH 409/659] +print --- src/script/sign.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 71fa4cee4..e4ec27688 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -42,11 +42,13 @@ TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keysto bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, const CKeyID& address, const CScript& scriptCode, uint32_t consensusBranchId, CKey *pprivKey, void *extraData) const { CKey key; + fprintf(stderr,"createsig\n"); if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) return false; - + fprintf(stderr,"createsig2\n"); + uint256 hash; try { hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, consensusBranchId); From 34878d8dbc95b4b95004fd7b45c92ae86bd14537 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 20:52:35 -1100 Subject: [PATCH 410/659] Reorder code --- src/script/sign.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index e4ec27688..d0ae52b3a 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -41,21 +41,18 @@ TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keysto bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, const CKeyID& address, const CScript& scriptCode, uint32_t consensusBranchId, CKey *pprivKey, void *extraData) const { - CKey key; - fprintf(stderr,"createsig\n"); - if (pprivKey) - key = *pprivKey; - else if (!keystore || !keystore->GetKey(address, key)) - return false; - fprintf(stderr,"createsig2\n"); - - uint256 hash; + CKey key; uint256 hash; try { hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, consensusBranchId); } catch (logic_error ex) { return false; } SIG_TXHASH = hash; + if (pprivKey) + key = *pprivKey; + else if (!keystore || !keystore->GetKey(address, key)) + return false; + if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; From ae0354d651c3ec46f0600ca60c0ff0f0d0f3572a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 21:16:04 -1100 Subject: [PATCH 411/659] Verify --- src/komodo_nSPV.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 67476f105..a141315ec 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + CPubKey pubkeys[64]; std::vector vchSig; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -443,11 +443,14 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini Date: Mon, 8 Jul 2019 21:23:27 -1100 Subject: [PATCH 412/659] Extract vchSig --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a141315ec..3d2628273 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; std::vector vchSig; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + CPubKey pubkeys[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -443,7 +443,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig(tx.vin[vini].scriptSig.begin(),mtx.vin[vini].scriptSig.end()); vchSig.pop_back(); for (j=0; j<64; j++) { From 933b352f042091a2b40c81c5df7c51fd243f5148 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 21:27:23 -1100 Subject: [PATCH 413/659] Extract --- src/komodo_nSPV.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3d2628273..b032f2b41 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + CPubKey pubkeys[64]; uint8_t *ptr; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -443,8 +443,16 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig(tx.vin[vini].scriptSig.begin(),mtx.vin[vini].scriptSig.end()); - vchSig.pop_back(); + ptr = tx.vin[vini].scriptSig.data(); + std::vector vchSig; + vchSig.resize(tx.vin[vini].scriptSig.size()-2); + for (j=0; j 0 && j < tx.vin[vini].scriptSig.size()-1 ) + vchSig[j-1] = ptr[j]; + fprintf(stderr,"%02x",ptr[j]); + } + fprintf(stderr," sig.%d\n",vini); for (j=0; j<64; j++) { NSPV_SignTx(mtx,vini,10000,scriptPubKeys[j]); From 193e9e14ebc29d9fb65482edfa4b7e640d61c15b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 21:28:41 -1100 Subject: [PATCH 414/659] ptr() --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b032f2b41..a44098869 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -443,7 +443,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig; vchSig.resize(tx.vin[vini].scriptSig.size()-2); for (j=0; j Date: Mon, 8 Jul 2019 21:29:37 -1100 Subject: [PATCH 415/659] Cast --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index a44098869..67b224b8f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -443,7 +443,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig; vchSig.resize(tx.vin[vini].scriptSig.size()-2); for (j=0; j Date: Mon, 8 Jul 2019 21:38:14 -1100 Subject: [PATCH 416/659] Test --- src/komodo_nSPV.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 67b224b8f..03d1f2208 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t *ptr; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,numsigs = 0; + CPubKey pubkeys[64]; uint8_t *ptr; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -445,14 +445,18 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { ptr = (uint8_t *)&tx.vin[vini].scriptSig; std::vector vchSig; - vchSig.resize(tx.vin[vini].scriptSig.size()-2); + siglen = ptr[16]; + vchSig.resize(siglen); for (j=0; j 0 && j < tx.vin[vini].scriptSig.size()-1 ) - vchSig[j-1] = ptr[j]; + if ( j > 17 && j < 17+siglen ) + vchSig[j-17] = ptr[j]; fprintf(stderr,"%02x",ptr[j]); } - fprintf(stderr," sig.%d\n",vini); + fprintf(stderr," sig.%d siglen.%d\n",vini,siglen); + for (j=0; j Date: Mon, 8 Jul 2019 21:52:04 -1100 Subject: [PATCH 417/659] Alternate way --- src/komodo_nSPV.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 03d1f2208..bc73bcc19 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t *ptr; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -443,19 +443,14 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini vchSig; - siglen = ptr[16]; - vchSig.resize(siglen); - for (j=0; j 17 && j < 17+siglen ) - vchSig[j-17] = ptr[j]; - fprintf(stderr,"%02x",ptr[j]); - } - fprintf(stderr," sig.%d siglen.%d\n",vini,siglen); + str = (char *)tx.vin[vini].scriptSig.ToString().c_str(); + fprintf(stderr,"scriptSig %s\n",str); + siglen = (int32_t)strlen(str)/2; + decode_hex(sig,siglen,str); + vchSig.resize(siglen-1); + memcpy(&vchSig[0],sig,siglen-1); for (j=0; j Date: Mon, 8 Jul 2019 21:54:30 -1100 Subject: [PATCH 418/659] vchSig --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index bc73bcc19..4375acd5f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector vchSig; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); From d40b7709bbc21a73043fd6318158e117fcef16ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 22:03:27 -1100 Subject: [PATCH 419/659] Printf casts --- src/komodo_bitcoind.h | 4 ++-- src/komodo_gateway.h | 6 +++--- src/komodo_utils.h | 4 ++-- src/main.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 48962b015..b3f870170 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2051,7 +2051,7 @@ uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height) total += txout.nValue; //fprintf(stderr, "MATCHED AmountPaid.%lu notaryid.%i\n",AmountToPay,NotarisationNotaries[n-1]); } - else fprintf(stderr, "NOT MATCHED AmountPaid.%lu AmountToPay.%lu notaryid.%i\n", pblock->vtx[0].vout[n].nValue, AmountToPay, NotarisationNotaries[n-1]); + else fprintf(stderr, "NOT MATCHED AmountPaid.%llu AmountToPay.%llu notaryid.%i\n", (long long)pblock->vtx[0].vout[n].nValue, (long long)AmountToPay, NotarisationNotaries[n-1]); } n++; } @@ -2347,7 +2347,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) numSN = komodo_notaries(notarypubkeys, height, pblock->nTime); if ( pblock->vtx[1].vin.size() < numSN/5 ) { - fprintf(stderr, "ht.%i does not meet minsigs.%i sigs.%li\n",height,numSN/5,pblock->vtx[1].vin.size()); + fprintf(stderr, "ht.%i does not meet minsigs.%i sigs.%lld\n",height,numSN/5,(long long)pblock->vtx[1].vin.size()); return(-1); } } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1006a9ada..5c60503bf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -669,7 +669,7 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) int32_t i; if ( sizeof(banned_txids)/sizeof(*banned_txids) > max ) { - fprintf(stderr,"komodo_bannedset: buffer too small %ld vs %d\n",sizeof(banned_txids)/sizeof(*banned_txids),max); + fprintf(stderr,"komodo_bannedset: buffer too small %d vs %d\n",(int32_t)(sizeof(banned_txids)/sizeof(*banned_txids)),max); StartShutdown(); } for (i=0; i indcounter %u, prevpos100 %u offset.%ld\n",datalen,validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); + fprintf(stderr,"datalen.%ld validated %ld -> indcounter %u, prevpos100 %u offset.%d\n",datalen,validated,indcounter,prevpos100,(int32_t)(indcounter * sizeof(uint32_t))); if ( fpos < datalen ) { fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 5a7bb75d1..3e2055204 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2125,7 +2125,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); if ( ASSETCHAINS_FOUNDERS_REWARD != 0 ) { - fprintf(stderr, "set founders reward.%li\n",ASSETCHAINS_FOUNDERS_REWARD); + fprintf(stderr, "set founders reward.%lld\n",(long long)ASSETCHAINS_FOUNDERS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS_REWARD),(void *)&ASSETCHAINS_FOUNDERS_REWARD); } } @@ -2348,7 +2348,7 @@ void komodo_args(char *argv0) if ( strcmp("PIRATE",ASSETCHAINS_SYMBOL) == 0 && ASSETCHAINS_HALVING[0] == 77777 ) { ASSETCHAINS_HALVING[0] *= 5; - fprintf(stderr,"PIRATE halving changed to %d %.1f days ASSETCHAINS_LASTERA.%lu\n",(int32_t)ASSETCHAINS_HALVING[0],(double)ASSETCHAINS_HALVING[0]/1440,ASSETCHAINS_LASTERA); + fprintf(stderr,"PIRATE halving changed to %d %.1f days ASSETCHAINS_LASTERA.%llu\n",(int32_t)ASSETCHAINS_HALVING[0],(double)ASSETCHAINS_HALVING[0]/1440,(long long)ASSETCHAINS_LASTERA); } else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) dpowconfs = 0; diff --git a/src/main.cpp b/src/main.cpp index 3a29edcf0..339f4e790 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -762,7 +762,7 @@ bool komodo_dailysnapshot(int32_t height) // include only top 3999 address. if ( vAddressSnapshot.size() > 3999 ) vAddressSnapshot.resize(3999); lastSnapShotHeight = undo_height; - fprintf(stderr, "vAddressSnapshot.size.%li\n", vAddressSnapshot.size()); + fprintf(stderr, "vAddressSnapshot.size.%d\n", (int32_t)vAddressSnapshot.size()); return true; } @@ -4322,7 +4322,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); StartShutdown(); } - fprintf(stderr, "snapshot completed in: %lu seconds\n", time(NULL)-start); + fprintf(stderr, "snapshot completed in: %d seconds\n", (int32_t)(time(NULL)-start)); } } return true; From ba444af9c4d2af638e1d0821f9938df74e447645 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 22:12:57 -1100 Subject: [PATCH 420/659] Fix --- src/komodo_nSPV.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4375acd5f..3453ad841 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -443,21 +443,20 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) } for (vini=0; vini Date: Mon, 8 Jul 2019 22:14:57 -1100 Subject: [PATCH 421/659] CScript:: --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3453ad841..fb82a5000 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -445,7 +445,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { CScript::const_iterator pc = tx.vin[vini].scriptSig.begin(); //CScript::const_iterator pend = tx.vin[vini].scriptSig.end(); - if ( GetPushedData(pc,vchSig) != 0 ) + if ( CScript::GetPushedData(pc,vchSig) != 0 ) { for (j=0; j Date: Mon, 8 Jul 2019 22:16:44 -1100 Subject: [PATCH 422/659] vData[0] --- src/komodo_nSPV.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fb82a5000..ebeea6f42 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector vchSig; + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector>& vData; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -445,15 +445,15 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { CScript::const_iterator pc = tx.vin[vini].scriptSig.begin(); //CScript::const_iterator pend = tx.vin[vini].scriptSig.end(); - if ( CScript::GetPushedData(pc,vchSig) != 0 ) + if ( CScript::GetPushedData(pc,vData) != 0 ) { - for (j=0; j Date: Mon, 8 Jul 2019 22:17:58 -1100 Subject: [PATCH 423/659] -& --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index ebeea6f42..3d39681fd 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector>& vData; + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector> vData; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); From d023823b90ea47950f282a09f462217f333ef666 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 22:19:16 -1100 Subject: [PATCH 424/659] tx.vin[vini].scriptSig --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 3d39681fd..1374003d4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -445,14 +445,14 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { CScript::const_iterator pc = tx.vin[vini].scriptSig.begin(); //CScript::const_iterator pend = tx.vin[vini].scriptSig.end(); - if ( CScript::GetPushedData(pc,vData) != 0 ) + if ( tx.vin[vini].scriptSig.GetPushedData(pc,vData) != 0 ) { for (j=0; j Date: Mon, 8 Jul 2019 22:24:17 -1100 Subject: [PATCH 425/659] vData[0] --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1374003d4..af16b94e4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -447,6 +447,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) //CScript::const_iterator pend = tx.vin[vini].scriptSig.end(); if ( tx.vin[vini].scriptSig.GetPushedData(pc,vData) != 0 ) { + vData[0].pop_back(); for (j=0; j Date: Mon, 8 Jul 2019 22:27:28 -1100 Subject: [PATCH 426/659] Test --- src/komodo_nSPV.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index af16b94e4..0f8c555d3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { - CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector> vData; + CPubKey pubkeys[64]; uint8_t sig[512]; char coinaddr[64]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,numsigs = 0; char *str; std::vector> vData; for (j=0; j<64; j++) { pubkeys[j] = buf2pk(elected[j]); @@ -453,8 +453,9 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) fprintf(stderr," vData[0]\n"); for (j=0; j<64; j++) { + Getscriptaddress(coinaddr,scriptPubKeys[j]); NSPV_SignTx(mtx,vini,10000,scriptPubKeys[j]); // sets SIG_TXHASH - fprintf(stderr,"%d ",pubkeys[j].Verify(SIG_TXHASH,vData[0])); + fprintf(stderr,"%s.%d ",coinaddr,pubkeys[j].Verify(SIG_TXHASH,vData[0])); } fprintf(stderr," verifies\n"); } From c4f95560b99914da381ccc12caad52d6525fc45b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 22:31:14 -1100 Subject: [PATCH 427/659] +prints --- src/komodo_nSPV.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 0f8c555d3..df697dc92 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -441,6 +441,9 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) pubkeys[j] = buf2pk(elected[j]); scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); } + fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); + for (vini=0; vini Date: Mon, 8 Jul 2019 22:40:28 -1100 Subject: [PATCH 428/659] Test --- src/komodo_nSPV.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index df697dc92..15f3ca911 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -440,6 +440,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { pubkeys[j] = buf2pk(elected[j]); scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); + fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j])); } fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); for (vini=0; vini Date: Mon, 8 Jul 2019 22:42:10 -1100 Subject: [PATCH 429/659] .c_str() --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 15f3ca911..aa1d0044b 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -440,7 +440,7 @@ int32_t NSPV_newnotariescount(CTransaction tx,uint8_t elected[64][33]) { pubkeys[j] = buf2pk(elected[j]); scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); - fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j])); + fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); } fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); for (vini=0; vini Date: Mon, 8 Jul 2019 23:01:06 -1100 Subject: [PATCH 430/659] NSPV_inforesult.H.nTime --- src/komodo_nSPV.h | 3 ++- src/komodo_nSPV_superlite.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index aa1d0044b..d0e9af6b4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -54,6 +54,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx); extern uint256 SIG_TXHASH; +uint32_t NSPV_blocktime(int32_t hdrheight); int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf) { @@ -518,7 +519,7 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * if ( opret.size() >= 32*2+4 ) { *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); - komodo_notaries(elected,*ntzheightp,0); + komodo_notaries(elected,*ntzheightp,NSPV_blocktime(*ntzheightp)); if ( verifyntz != 0 && (numsigs= NSPV_newnotariescount(tx,elected)) < 12 ) { fprintf(stderr,"numsigs.%d error\n",numsigs); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index a50b7c44c..5a76cf912 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -386,6 +386,20 @@ UniValue NSPV_getinfo_req(int32_t reqht) return(NSPV_getinfo_json(&NSPV_inforesult)); } +uint32_t NSPV_blocktime(int32_t hdrheight) +{ + if ( hdrheight > 0 ) + { + NSPV_getinfo_req(hdrheight) + if ( NSPV_inforesult.hdrheight == hdrheight ) + { + fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); + return(NSPV_inforesult.H.nTime); + } + } + return(0); +} + UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; From fd679b6f0e8c6dda0958a374864b0b920dee6227 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:04:44 -1100 Subject: [PATCH 431/659] Test --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5a76cf912..75fffb761 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -390,7 +390,7 @@ uint32_t NSPV_blocktime(int32_t hdrheight) { if ( hdrheight > 0 ) { - NSPV_getinfo_req(hdrheight) + NSPV_getinfo_req(hdrheight); if ( NSPV_inforesult.hdrheight == hdrheight ) { fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); From b31ef7ec9c0094e260e2ced411e0789f8c557be8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:14:50 -1100 Subject: [PATCH 432/659] -print --- src/komodo_nSPV.h | 76 ++++++++++++++++++------------------- src/komodo_nSPV_superlite.h | 2 +- src/komodo_nSPV_wallet.h | 4 +- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d0e9af6b4..614bd510a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -424,6 +424,43 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) else return(-1); } +bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); + +int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) +{ + CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,retval; uint64_t mask = 0; char *str; std::vector> vData; + for (j=0; j<64; j++) + { + pubkeys[j] = buf2pk(elected[j]); + scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); + //fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); + } + //fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); + for (vini=0; vini> vData; - for (j=0; j<64; j++) - { - pubkeys[j] = buf2pk(elected[j]); - scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); - fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); - } - fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); - for (vini=0; vini t%u\n",hdrheight,NSPV_inforesult.H.nTime); + //fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); return(NSPV_inforesult.H.nTime); } } diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 0a8ca30d2..6115132af 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -135,9 +135,9 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) { UpdateTransaction(mtx,vini,sigdata); - fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + // fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); - } else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + } // else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); } From 6ecb8ee9ab7ea8c24034da6b4825ad611752501d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:16:07 -1100 Subject: [PATCH 433/659] Mask --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 614bd510a..9a9e5702a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -458,7 +458,7 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) //fprintf(stderr," verifies\n"); } } - return(bitweight(numsigs)); + return(bitweight(mask)); } /* From 00115fddeca4e91b71425070cf82998a882ed038 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:23:52 -1100 Subject: [PATCH 434/659] Test --- src/komodo_nSPV.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9a9e5702a..06527e870 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -436,8 +436,8 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) //fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); } //fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); - for (vini=0; vini Date: Mon, 8 Jul 2019 23:26:15 -1100 Subject: [PATCH 435/659] Taxied --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 06527e870..8a66368bd 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -435,7 +435,7 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) scriptPubKeys[j] = (CScript() << ParseHex(HexStr(pubkeys[j])) << OP_CHECKSIG); //fprintf(stderr,"%d %s\n",j,HexStr(pubkeys[j]).c_str()); } - //fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); + fprintf(stderr,"txid %s\n",tx.GetHash().GetHex().c_str()); //for (vini=0; vini Date: Mon, 8 Jul 2019 23:29:53 -1100 Subject: [PATCH 436/659] sleep(1); --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_superlite.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 8a66368bd..4ac20183b 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -520,6 +520,7 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4 ) { + sleep(1); *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); komodo_notaries(elected,*ntzheightp,NSPV_blocktime(*ntzheightp)); if ( verifyntz != 0 && (numsigs= NSPV_fastnotariescount(tx,elected)) < 12 ) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5c29fde7a..75fffb761 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -393,7 +393,7 @@ uint32_t NSPV_blocktime(int32_t hdrheight) NSPV_getinfo_req(hdrheight); if ( NSPV_inforesult.hdrheight == hdrheight ) { - //fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); + fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); return(NSPV_inforesult.H.nTime); } } From 86e8e39e6fdba454dc5db5cff34dd9e942e10e85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:33:29 -1100 Subject: [PATCH 437/659] Always full validation --- src/komodo_nSPV.h | 2 -- src/komodo_nSPV_wallet.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4ac20183b..333f384f2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -20,7 +20,6 @@ // interest calculations are currently just using what is returned, it should calculate it from scratch -// bruteforce sig -> NN pubkey validator // CC signing // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) @@ -28,7 +27,6 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_SKIPFULLVALIDATION 0 // changing to 0 issues 26 remote gettx, per utxo! need local bruteforcer #define NSPV_POLLITERS 10 #define NSPV_POLLMICROS 100777 #define NSPV_MAXVINS 64 diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 6115132af..5ac4081f5 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -165,7 +165,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf utxovout = mtx.vin[i].prevout.n; if ( i > 0 ) sleep(1); - validation = NSPV_gettransaction(NSPV_SKIPFULLVALIDATION,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); + validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security { From 710ef083105d3d70912d73002eede46a44904479 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:46:19 -1100 Subject: [PATCH 438/659] Support presapling notarisations --- src/cc/CCinclude.h | 2 +- src/cc/CCtx.cpp | 2 +- src/komodo_nSPV.h | 13 +++++++------ src/komodo_nSPV_wallet.h | 15 ++++++++++----- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index a6dbba1a3..4c6791676 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -290,7 +290,7 @@ void SetCCtxids(std::vector > &addressIndex int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs); int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag); -bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); +bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime); // curve25519 and sha256 bits256 curve25519_shared(bits256 privkey,bits256 otherpub); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 3f0bb6a9d..3931e19b4 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -160,7 +160,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran } else { - if ( NSPV_SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) + if ( NSPV_SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey,0) == 0 ) fprintf(stderr,"NSPV signing error for vini.%d of %llx\n",i,(long long)vinimask); } } diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 333f384f2..d4a4fd90f 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -422,9 +422,9 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) else return(-1); } -bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey); +bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime); -int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) +int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33],uint32_t nTime) { CPubKey pubkeys[64]; uint8_t sig[512]; CScript scriptPubKeys[64]; CMutableTransaction mtx(tx); int32_t vini,j,siglen,retval; uint64_t mask = 0; char *str; std::vector> vData; for (j=0; j<64; j++) @@ -447,7 +447,7 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33]) if ( ((1LL << j) & mask) != 0 ) continue; char coinaddr[64]; Getscriptaddress(coinaddr,scriptPubKeys[j]); - NSPV_SignTx(mtx,vini,10000,scriptPubKeys[j]); // sets SIG_TXHASH + NSPV_SignTx(mtx,vini,10000,scriptPubKeys[j],nTime); // sets SIG_TXHASH if ( (retval= pubkeys[j].Verify(SIG_TXHASH,vData[0])) != 0 ) { fprintf(stderr,"(vini.%d %s.%d) ",vini,coinaddr,retval); @@ -511,7 +511,7 @@ uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std: int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 *blockhashp,uint256 *desttxidp,CTransaction tx) { - int32_t numsigs=0; uint8_t elected[64][33]; char *symbol; std::vector opret; + int32_t numsigs=0; uint8_t elected[64][33]; char *symbol; std::vector opret; uint32_t nTime; if ( tx.vout.size() >= 2 ) { symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; @@ -520,8 +520,9 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * { sleep(1); *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); - komodo_notaries(elected,*ntzheightp,NSPV_blocktime(*ntzheightp)); - if ( verifyntz != 0 && (numsigs= NSPV_fastnotariescount(tx,elected)) < 12 ) + nTime = NSPV_blocktime(*ntzheightp); + komodo_notaries(elected,*ntzheightp,nTime); + if ( verifyntz != 0 && (numsigs= NSPV_fastnotariescount(tx,elected,nTime)) < 12 ) { fprintf(stderr,"numsigs.%d error\n",numsigs); return(-3); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 5ac4081f5..21b577707 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -121,9 +121,9 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 return(0); } -bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) +bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime) { - CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; + CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; int64_t branchid = NSPV_BRANCHID; keystore.AddKey(NSPV_key); if ( 0 ) { @@ -132,7 +132,12 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C fprintf(stderr,"%02x",((uint8_t *)&scriptPubKey)[i]); fprintf(stderr," scriptPubKey\n"); } - if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,NSPV_BRANCHID) != 0 ) + if ( nTime < KOMODO_SAPLING_ACTIVATION ) + { + fprintf(stderr,"use legacy sig validation\n"); + branchid = 0; + } + if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,branchid) != 0 ) { UpdateTransaction(mtx,vini,sigdata); // fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); @@ -179,7 +184,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf fprintf(stderr,"vintx vout mismatch %d != %d\n",utxovout,used[i].vout); return(""); } - else if ( NSPV_SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) + else if ( NSPV_SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey,0) == 0 ) { fprintf(stderr,"signing error for vini.%d\n",i); return(""); @@ -259,7 +264,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a result.push_back(Pair("error","wif expired")); return(result); } - hex = NSPV_signtx(retcodes,mtx,txfee,opret,used); + hex = NSPV_signtx(retcodes,mtx,txfee,opret,used,0); if ( hex.size() > 0 ) { if ( DecodeHexTx(tx,hex) != 0 ) From ba4f380d66c7459b247c1a103281d7247d794c46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 23:51:02 -1100 Subject: [PATCH 439/659] Fix --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 21b577707..e0a477ed3 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -264,7 +264,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a result.push_back(Pair("error","wif expired")); return(result); } - hex = NSPV_signtx(retcodes,mtx,txfee,opret,used,0); + hex = NSPV_signtx(retcodes,mtx,txfee,opret,used); if ( hex.size() > 0 ) { if ( DecodeHexTx(tx,hex) != 0 ) From c1bbe1421c53d66a300fcab857c4fd7488c232cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 00:45:22 -1100 Subject: [PATCH 440/659] Fullnode shouldn't issue getnSPV calls --- src/komodo_nSPV_superlite.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 75fffb761..2563f1253 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -155,6 +155,8 @@ UniValue NSPV_logout() void komodo_nSPV(CNode *pto) // polling loop from SendMessages { uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); + if ( KOMODO_NSPV == 0 ) + return; if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT ) NSPV_logout(); if ( (pto->nServices & NODE_NSPV) == 0 ) From c45bb97ce8c66de49c3d4cde459a5c0b827b3406 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 00:53:56 -1100 Subject: [PATCH 441/659] -fullnode doing nSPV client --- src/komodo_nSPV_superlite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 2563f1253..6ab42b272 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -102,6 +102,8 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL); + if ( KOMODO_NSPV == 0 ) + return(0); if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); @@ -155,8 +157,6 @@ UniValue NSPV_logout() void komodo_nSPV(CNode *pto) // polling loop from SendMessages { uint8_t msg[256]; int32_t i,len=0; uint32_t timestamp = (uint32_t)time(NULL); - if ( KOMODO_NSPV == 0 ) - return; if ( NSPV_logintime != 0 && timestamp > NSPV_logintime+NSPV_AUTOLOGOUT ) NSPV_logout(); if ( (pto->nServices & NODE_NSPV) == 0 ) From c34dd538bb3f31319ffe51a7257cc51e005c3a58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 00:54:31 -1100 Subject: [PATCH 442/659] Test --- src/komodo_nSPV_superlite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 6ab42b272..005193681 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -102,8 +102,8 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL); - if ( KOMODO_NSPV == 0 ) - return(0); + //if ( KOMODO_NSPV == 0 ) + // return(0); if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); From fc3c50c02e8e3dd2f9ab2380873f64e2e3f7cae8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:00:39 -1100 Subject: [PATCH 443/659] No services bug? --- src/net.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net.cpp b/src/net.cpp index 0586d7124..56de05b83 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -458,7 +458,7 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); -//fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); +fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); } From ec24982ff6ff4403ed86745d2367f90ac622bc77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:02:35 -1100 Subject: [PATCH 444/659] +print --- src/komodo_nSPV_superlite.h | 4 ++-- src/net.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 005193681..6ab42b272 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -102,8 +102,8 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL); - //if ( KOMODO_NSPV == 0 ) - // return(0); + if ( KOMODO_NSPV == 0 ) + return(0); if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); diff --git a/src/net.cpp b/src/net.cpp index 56de05b83..3bd9e4b19 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -458,7 +458,7 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); -fprintf(stderr,"PUSH services.%llx\n",(long long)nLocalServices); +fprintf(stderr,"KOMODO_NSPV.%d PUSH services.%llx\n",KOMODO_NSPV,(long long)nLocalServices); } From 94a1656ed280c452d257a8f9cdf9d111165363c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:04:43 -1100 Subject: [PATCH 445/659] Extern --- src/net.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index 3bd9e4b19..0c5612bb1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -444,6 +444,8 @@ void CNode::CloseSocketDisconnect() vRecvMsg.clear(); } +extern int32_t KOMODO_NSPV; + void CNode::PushVersion() { int nBestHeight = g_signals.GetHeight().get_value_or(0); From bab3e6a1b800bffc4d070d9296830f7270a50fc1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:07:27 -1100 Subject: [PATCH 446/659] +print --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 339f4e790..ac5b8b48b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7245,6 +7245,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if ( KOMODO_NSPV != 0 ) { + fprintf(stderr,"peer nServices.%llx nSPV peer.%d\n",(long long)pform->nServices,pfrom->id); if ( (pfrom->nServices & NODE_NSPV) == 0 ) { //fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); From 794839f38e9d9097cf3f4743042a9518de2fb93d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:09:06 -1100 Subject: [PATCH 447/659] From --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ac5b8b48b..2ef31147e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7245,7 +7245,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if ( KOMODO_NSPV != 0 ) { - fprintf(stderr,"peer nServices.%llx nSPV peer.%d\n",(long long)pform->nServices,pfrom->id); + fprintf(stderr,"peer nServices.%llx nSPV peer.%d\n",(long long)pfrom->nServices,pfrom->id); if ( (pfrom->nServices & NODE_NSPV) == 0 ) { //fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); From d7abeff40cfef8a45a5e12280d4b719818fa58e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:12:51 -1100 Subject: [PATCH 448/659] Test --- src/init.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 738d94377..4adde6681 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1147,9 +1147,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Option to startup with mocktime set (used for regression testing): SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op - if (GetBoolArg("-peerbloomfilters", true)) - nLocalServices |= NODE_BLOOM; - + if ( KOMODO_NSPV == 0 ) + { + if (GetBoolArg("-peerbloomfilters", true)) + nLocalServices |= NODE_BLOOM; + } nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); #ifdef ENABLE_MINING From 70e6b596fe4e946058ce2bd49e2214fc4ee4c55d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:16:44 -1100 Subject: [PATCH 449/659] +print --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 6ab42b272..56157e32d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -102,8 +102,8 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL); - if ( KOMODO_NSPV == 0 ) - return(0); + //if ( KOMODO_NSPV == 0 ) + // return(0); if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); @@ -131,7 +131,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - //fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); + fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; return(pnode); From f89ebce1e7b47cb74d5b4875f8d6fe22efc6bd56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:22:41 -1100 Subject: [PATCH 450/659] -print --- src/komodo_nSPV_superlite.h | 3 ++- src/net.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 56157e32d..9a30ddc44 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -131,7 +131,8 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); + if ( KOMODO_NSPV == 0 ) + fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; return(pnode); diff --git a/src/net.cpp b/src/net.cpp index 0c5612bb1..23d20e4c0 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -460,7 +460,7 @@ void CNode::PushVersion() LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true); -fprintf(stderr,"KOMODO_NSPV.%d PUSH services.%llx\n",KOMODO_NSPV,(long long)nLocalServices); +//fprintf(stderr,"KOMODO_NSPV.%d PUSH services.%llx\n",KOMODO_NSPV,(long long)nLocalServices); } From 53728f1bb503e9d06435b0ab34af4853f9ba95df Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:26:35 -1100 Subject: [PATCH 451/659] -print --- src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2ef31147e..b4ecc6922 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7245,10 +7245,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if ( KOMODO_NSPV != 0 ) { - fprintf(stderr,"peer nServices.%llx nSPV peer.%d\n",(long long)pfrom->nServices,pfrom->id); if ( (pfrom->nServices & NODE_NSPV) == 0 ) { - //fprintf(stderr,"invalid nSPV peer.%d\n",pfrom->id); + // fprintf(stderr,"invalid nServices.%llx nSPV peer.%d\n",(long long)pfrom->nServices,pfrom->id); pfrom->fDisconnect = true; return false; } From ecc5aebc444b57bf64d5d9df6e84fd00168dee8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 01:52:25 -1100 Subject: [PATCH 452/659] Disp relay tx --- src/komodo_nSPV_fullnode.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index cdfb0f57e..436095945 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -214,7 +214,10 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int if ( myAddtomempool(tx) != 0 ) ptr->retcode = 1; else ptr->retcode = 0; - //fprintf(stderr,"relay transaction %s retcode.%d\n",ptr->txid.GetHex().c_str(),ptr->retcode); + int32_t i; + for (i=0; itxid.GetHex().c_str(),ptr->retcode); RelayTransaction(tx); } else ptr->retcode = -1; return(sizeof(*ptr)); From 9a3cf79c3760fb3ff8a70f7f29340bba520345ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 02:00:15 -1100 Subject: [PATCH 453/659] Test --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_fullnode.h | 16 +++++++++------- src/net.cpp | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d4a4fd90f..e0a003fcd 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -23,6 +23,7 @@ // CC signing // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) +// bug: under load, fullnode was returning all 0 nServices #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 436095945..948846fe5 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -210,15 +210,17 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int { LOCK(cs_main); ptr->txid = tx.GetHash(); - fprintf(stderr,"addmempool transaction %s\n",ptr->txid.GetHex().c_str()); + fprintf(stderr,"try to addmempool transaction %s\n",ptr->txid.GetHex().c_str()); if ( myAddtomempool(tx) != 0 ) + { + int32_t i; + for (i=0; itxid.GetHex().c_str(),ptr->retcode); ptr->retcode = 1; - else ptr->retcode = 0; - int32_t i; - for (i=0; itxid.GetHex().c_str(),ptr->retcode); - RelayTransaction(tx); + RelayTransaction(tx); + } else ptr->retcode = -3; + } else ptr->retcode = -1; return(sizeof(*ptr)); } diff --git a/src/net.cpp b/src/net.cpp index 23d20e4c0..02cddd3e2 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1843,7 +1843,7 @@ bool StopNode() for (int i=0; ipost(); - if (fAddressesInitialized) + if (KOMODO_NSPV == 0 && fAddressesInitialized) { DumpAddresses(); fAddressesInitialized = false; From 7e47549603bc04ded54228c56a590cb8ccb7c730 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 02:04:54 -1100 Subject: [PATCH 454/659] Fix signing legacy check --- src/komodo_nSPV_wallet.h | 2 +- src/main.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index e0a477ed3..6cf2e82c6 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -132,7 +132,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C fprintf(stderr,"%02x",((uint8_t *)&scriptPubKey)[i]); fprintf(stderr," scriptPubKey\n"); } - if ( nTime < KOMODO_SAPLING_ACTIVATION ) + if ( nTime != 0 && nTime < KOMODO_SAPLING_ACTIVATION ) { fprintf(stderr,"use legacy sig validation\n"); branchid = 0; diff --git a/src/main.cpp b/src/main.cpp index b4ecc6922..a8ff33c2b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3974,7 +3974,8 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) { void FlushStateToDisk() { CValidationState state; - FlushStateToDisk(state, FLUSH_STATE_ALWAYS); + if ( KOMODO_NSPV == 0 ) + FlushStateToDisk(state, FLUSH_STATE_ALWAYS); } void PruneAndFlush() { From c792649129e3a1a4f774fbe23f27f8b0f40c0bc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 02:10:58 -1100 Subject: [PATCH 455/659] -print --- src/komodo_nSPV_fullnode.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 948846fe5..0d540e06d 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -210,14 +210,14 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int { LOCK(cs_main); ptr->txid = tx.GetHash(); - fprintf(stderr,"try to addmempool transaction %s\n",ptr->txid.GetHex().c_str()); + //fprintf(stderr,"try to addmempool transaction %s\n",ptr->txid.GetHex().c_str()); if ( myAddtomempool(tx) != 0 ) { - int32_t i; - for (i=0; itxid.GetHex().c_str(),ptr->retcode); ptr->retcode = 1; + //int32_t i; + //for (i=0; itxid.GetHex().c_str(),ptr->retcode); RelayTransaction(tx); } else ptr->retcode = -3; From 4ff591e40df5c995c655f5017217d311da7cf427 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 9 Jul 2019 16:07:25 +0200 Subject: [PATCH 456/659] EARLYTXID fixes (#28) --- src/bitcoind.cpp | 7 ++++++- src/cc/pegs.cpp | 14 +++++++------- src/komodo_utils.h | 8 +------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index ff329a0d6..f0055d7fd 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -68,8 +68,13 @@ void komodo_cbopretupdate(int32_t forceflag); void WaitForShutdown(boost::thread_group* threadGroup) { - int32_t i; bool fShutdown = ShutdownRequested(); + int32_t i,height; bool fShutdown = ShutdownRequested(); const uint256 zeroid; // Tell the main threads to shutdown. + if (komodo_currentheight()>100 && KOMODO_EARLYTXID!=zeroid && ((height=tx_height(KOMODO_EARLYTXID))==0 || height>100)) + { + fprintf(stderr,"error: earlytx must be before block height 100 or tx does not exist\n"); + StartShutdown(); + } if ( ASSETCHAINS_CBOPRET != 0 ) komodo_pricesinit(); while (!fShutdown) diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 2e658fd0a..96c41b9ff 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -86,12 +86,12 @@ pegs CC is able to create a coin backed (by any supported coin with gateways CC */ // start of consensus code -#ifndef PEGS_TRSHOLDS -#define PEGS_TRSHOLDS +#ifndef PEGS_THRESHOLDS +#define PEGS_THRESHOLDS #define PEGS_ACCOUNT_YELLOW_ZONE 60 -#define PEGS_ACCOUNT_TRESHOLD 90 -#define PEGS_GLOBAL_TRESHOLD 60 -#endif // PEGS_TRSHOLDS +#define PEGS_ACCOUNT_THRESHOLD 90 +#define PEGS_GLOBAL_THRESHOLD 60 +#endif // PEGS_THRESHOLDS #define CC_MARKER_VALUE 10000 extern uint64_t ASSETCHAINS_PEGSCCPARAMS[3]; @@ -1154,9 +1154,9 @@ std::string PegsLiquidate(uint64_t txfee,uint256 pegstxid, uint256 tokenid, uint LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - if (PegsGetAccountRatio(pegstxid,tokenid,liquidatetxid)<(ASSETCHAINS_PEGSCCPARAMS[0]?ASSETCHAINS_PEGSCCPARAMS[0]:PEGS_ACCOUNT_TRESHOLD) || PegsGetGlobalRatio(pegstxid)<(ASSETCHAINS_PEGSCCPARAMS[1]?ASSETCHAINS_PEGSCCPARAMS[1]:PEGS_GLOBAL_TRESHOLD)) + if (PegsGetAccountRatio(pegstxid,tokenid,liquidatetxid)<(ASSETCHAINS_PEGSCCPARAMS[0]?ASSETCHAINS_PEGSCCPARAMS[0]:PEGS_ACCOUNT_THRESHOLD) || PegsGetGlobalRatio(pegstxid)<(ASSETCHAINS_PEGSCCPARAMS[1]?ASSETCHAINS_PEGSCCPARAMS[1]:PEGS_GLOBAL_THRESHOLD)) { - CCerror = strprintf("not able to liquidate account until account ratio > %lu%% and global ratio > %lu%%",(ASSETCHAINS_PEGSCCPARAMS[0]?ASSETCHAINS_PEGSCCPARAMS[0]:PEGS_ACCOUNT_TRESHOLD),(ASSETCHAINS_PEGSCCPARAMS[1]?ASSETCHAINS_PEGSCCPARAMS[1]:PEGS_GLOBAL_TRESHOLD)); + CCerror = strprintf("not able to liquidate account until account ratio > %lu%% and global ratio > %lu%%",(ASSETCHAINS_PEGSCCPARAMS[0]?ASSETCHAINS_PEGSCCPARAMS[0]:PEGS_ACCOUNT_THRESHOLD),(ASSETCHAINS_PEGSCCPARAMS[1]?ASSETCHAINS_PEGSCCPARAMS[1]:PEGS_GLOBAL_THRESHOLD)); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 5a7bb75d1..686b2fbde 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1787,13 +1787,7 @@ void komodo_args(char *argv0) { printf("KOMODO_REWIND %d\n",KOMODO_REWIND); } - KOMODO_EARLYTXID = Parseuint256(GetArg("-earlytxid","0").c_str()); - CTransaction tx; uint256 blockhash; - if (KOMODO_EARLYTXID!=zeroid && myGetTransaction(KOMODO_EARLYTXID,tx,blockhash) && (mapBlockIndex[blockhash]->GetHeight() == 0 || mapBlockIndex[blockhash]->GetHeight() > 100)) - { - fprintf(stderr,"error: earlytx can be only in first 100 blocks or tx does not exist\n"); - StartShutdown(); - } + KOMODO_EARLYTXID = Parseuint256(GetArg("-earlytxid","0").c_str()); ASSETCHAINS_EARLYTXIDCONTRACT = GetArg("-ac_earlytxidcontract",0); if ( name.c_str()[0] != 0 ) { From 3a3bb52b7f9cede3ed7a3f159f63da0100fbd009 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 05:02:44 -1100 Subject: [PATCH 457/659] KOMODO_EARLYTXID_HEIGHT 200 --- src/bitcoind.cpp | 2 +- src/komodo_defs.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index f0055d7fd..a356e20a7 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -70,7 +70,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) { int32_t i,height; bool fShutdown = ShutdownRequested(); const uint256 zeroid; // Tell the main threads to shutdown. - if (komodo_currentheight()>100 && KOMODO_EARLYTXID!=zeroid && ((height=tx_height(KOMODO_EARLYTXID))==0 || height>100)) + if (komodo_currentheight()>KOMODO_EARLYTXID_HEIGHT && KOMODO_EARLYTXID!=zeroid && ((height=tx_height(KOMODO_EARLYTXID))==0 || height>KOMODO_EARLYTXID_HEIGHT)) { fprintf(stderr,"error: earlytx must be before block height 100 or tx does not exist\n"); StartShutdown(); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 06ed750a5..001ee0dce 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -17,6 +17,7 @@ #define KOMODO_DEFS_H #include "komodo_nk.h" +#define KOMODO_EARLYTXID_HEIGHT 200 #define ASSETCHAINS_MINHEIGHT 128 #define ASSETCHAINS_MAX_ERAS 7 #define KOMODO_ELECTION_GAP 2000 From 6862fbcd1d0fc6c53eb64ef99d91d281a179b741 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 05:54:49 -1100 Subject: [PATCH 458/659] More patience --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e0a003fcd..e9253a167 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -28,8 +28,8 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_POLLITERS 10 -#define NSPV_POLLMICROS 100777 +#define NSPV_POLLITERS 15 +#define NSPV_POLLMICROS 100000 #define NSPV_MAXVINS 64 #define NSPV_AUTOLOGOUT 777 #define NSPV_BRANCHID 0x76b809bb From a79d415babffb0154fbe03828a331a31c20a6da9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 05:56:03 -1100 Subject: [PATCH 459/659] Prevent getnSPV from full nodes --- src/komodo_nSPV_superlite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 9a30ddc44..66e921f4d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -102,8 +102,8 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) { int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL); - //if ( KOMODO_NSPV == 0 ) - // return(0); + if ( KOMODO_NSPV == 0 ) + return(0); if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); From 3596b0d021af1292247d41da5a158b31aadb0bc0 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Tue, 9 Jul 2019 22:17:00 +0200 Subject: [PATCH 460/659] fix ac_cbmaturity magic without other params --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index dbbc9ecaf..57d652309 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2041,7 +2041,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); StartShutdown(); } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; From 177902aa8aa21b866229b759697234a3a2fff7fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 21:32:46 -1100 Subject: [PATCH 461/659] Validate KMD rewards --- src/komodo_nSPV.h | 4 ++-- src/komodo_nSPV_superlite.h | 16 +++++++++++++--- src/komodo_nSPV_wallet.h | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e9253a167..2d50dec26 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -51,7 +51,7 @@ #define NSPV_BROADCAST 0x0c #define NSPV_BROADCASTRESP 0x0d -int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx); +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime); extern uint256 SIG_TXHASH; uint32_t NSPV_blocktime(int32_t hdrheight); @@ -475,7 +475,7 @@ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) for (i=0; i response) // received a r NSPV_inforesult = I; } else if ( NSPV_inforesult.height > I.height ) + { NSPV_lastinfo = timestamp - ASSETCHAINS_BLOCKTIME/4; + // need to validate new header to make sure it is valid mainchain + if ( NSPV_inforesult.height == NSPV_inforesult.hdrheight ) + NSPV_tiptime = NSPV_inforesult.hdr.nTime; + } break; case NSPV_UTXOSRESP: NSPV_utxosresp_purge(&NSPV_utxosresult); @@ -604,9 +609,9 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) return(0); } -int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx) +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime) { - int32_t i,offset,retval = 0; std::vector proof; + int32_t i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; for (i=0; i<3; i++) { NSPV_txproof(vout,txid,height); @@ -623,6 +628,11 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int retval = -2000; else if ( skipvalidation == 0 && NSPV_txproofresult.unspentvalue <= 0 ) retval = -2001; + else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) + { + rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); + fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); + } else if ( skipvalidation == 0 ) { if ( NSPV_txproofresult.txprooflen > 0 ) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 6cf2e82c6..c38b29598 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -170,7 +170,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf utxovout = mtx.vin[i].prevout.n; if ( i > 0 ) sleep(1); - validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx); + validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,used[i].extradata,NSPV_tiptime); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security { From ee266ad84f2b8210e40df0101545d6dca8bd7158 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 21:34:59 -1100 Subject: [PATCH 462/659] H --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index b81250424..5e8821712 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -63,7 +63,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r NSPV_lastinfo = timestamp - ASSETCHAINS_BLOCKTIME/4; // need to validate new header to make sure it is valid mainchain if ( NSPV_inforesult.height == NSPV_inforesult.hdrheight ) - NSPV_tiptime = NSPV_inforesult.hdr.nTime; + NSPV_tiptime = NSPV_inforesult.H.nTime; } break; case NSPV_UTXOSRESP: From 8ef296a93e9c590b09d43efc43879f7ddfbad751 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 21:47:52 -1100 Subject: [PATCH 463/659] Da --- src/komodo_nSPV_superlite.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5e8821712..302928b3f 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -27,7 +27,7 @@ int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr); uint32_t NSPV_lastinfo,NSPV_logintime,NSPV_tiptime; CKey NSPV_key; -char NSPV_wifstr[64],NSPV_pubkeystr[67]; +char NSPV_wifstr[64],NSPV_pubkeystr[67],NSPV_lastpeer[128]; std::string NSPV_address; struct NSPV_inforesp NSPV_inforesult; struct NSPV_utxosresp NSPV_utxosresult; @@ -43,6 +43,7 @@ struct NSPV_broadcastresp NSPV_broadcastresult; void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a response { struct NSPV_inforesp I; int32_t len; uint32_t timestamp = (uint32_t)time(NULL); + strncpy(NSPV_lastpeer,pfrom->addr.ToString().c_str(),sizeof(NSPV_lastpeer)-1); if ( (len= response.size()) > 0 ) { switch ( response[0] ) @@ -191,6 +192,7 @@ UniValue NSPV_txproof_json(struct NSPV_txproof *ptr) result.push_back(Pair("height",(int64_t)ptr->height)); result.push_back(Pair("txlen",(int64_t)ptr->txlen)); result.push_back(Pair("txprooflen",(int64_t)ptr->txprooflen)); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -205,6 +207,7 @@ UniValue NSPV_spentinfo_json(struct NSPV_spentinfo *ptr) result.push_back(Pair("spentvini",(int64_t)ptr->spentvini)); result.push_back(Pair("spenttxlen",(int64_t)ptr->spent.txlen)); result.push_back(Pair("spenttxprooflen",(int64_t)ptr->spent.txprooflen)); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -258,6 +261,7 @@ UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr) result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); result.push_back(Pair("header",NSPV_header_json(&ptr->H,ptr->hdrheight))); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -290,6 +294,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) result.push_back(Pair("balance",(double)ptr->total/COIN)); if ( ASSETCHAINS_SYMBOL[0] == 0 ) result.push_back(Pair("interest",(double)ptr->interest/COIN)); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -299,6 +304,7 @@ UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr) result.push_back(Pair("result","success")); result.push_back(Pair("prev",NSPV_ntz_json(&ptr->prevntz))); result.push_back(Pair("next",NSPV_ntz_json(&ptr->nextntz))); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -316,6 +322,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("nexttxlen",(int64_t)ptr->prevtxlen)); result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -332,8 +339,10 @@ UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid) case 0: result.push_back(Pair("type","broadcast")); break; case -1: result.push_back(Pair("type","decode error")); break; case -2: result.push_back(Pair("type","timeout")); break; + case -2: result.push_back(Pair("type","error adding to mempool")); break; default: result.push_back(Pair("type","unknown")); break; } + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -396,15 +405,19 @@ UniValue NSPV_getinfo_req(int32_t reqht) uint32_t NSPV_blocktime(int32_t hdrheight) { + uint32_t timestamp; struct NSPV_inforesp old = NSPV_inforesult; if ( hdrheight > 0 ) { NSPV_getinfo_req(hdrheight); if ( NSPV_inforesult.hdrheight == hdrheight ) { - fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,NSPV_inforesult.H.nTime); - return(NSPV_inforesult.H.nTime); + timestamp = NSPV_inforesult.H.nTime; + NSPV_inforesult = old; + fprintf(stderr,"NSPV_blocktime ht.%d -> t%u\n",hdrheight,timestamp); + return(timestamp); } } + NSPV_inforesult = old; return(0); } From ff60331104dfbba158474300830d808fc3af6d6f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 21:49:01 -1100 Subject: [PATCH 464/659] -3 --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 302928b3f..10c6c16b2 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -339,7 +339,7 @@ UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid) case 0: result.push_back(Pair("type","broadcast")); break; case -1: result.push_back(Pair("type","decode error")); break; case -2: result.push_back(Pair("type","timeout")); break; - case -2: result.push_back(Pair("type","error adding to mempool")); break; + case -3: result.push_back(Pair("type","error adding to mempool")); break; default: result.push_back(Pair("type","unknown")); break; } result.push_back(Pair("lastpeer",NSPV_lastpeer)); From e6b1b310e9d8073642277a73a28052ee5b67c91b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:16:31 -1100 Subject: [PATCH 465/659] Fix control flow --- src/komodo_nSPV_superlite.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 10c6c16b2..38522d74d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -646,7 +646,8 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); } - else if ( skipvalidation == 0 ) + + if ( skipvalidation == 0 ) { if ( NSPV_txproofresult.txprooflen > 0 ) { From d8b568683c8f19446c073f7fffac10315b586a41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:26:27 -1100 Subject: [PATCH 466/659] Display rewards vs validated --- src/komodo_nSPV.h | 6 +++--- src/komodo_nSPV_superlite.h | 8 ++++++-- src/komodo_nSPV_wallet.h | 14 ++++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 2d50dec26..2aec951ba 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -51,7 +51,7 @@ #define NSPV_BROADCAST 0x0c #define NSPV_BROADCASTRESP 0x0d -int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime); +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum); extern uint256 SIG_TXHASH; uint32_t NSPV_blocktime(int32_t hdrheight); @@ -471,11 +471,11 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33],uint32_t */ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { - uint8_t *script; CTransaction vintx; int32_t i,j,utxovout,scriptlen,numsigs = 0; + uint8_t *script; CTransaction vintx; int64_t rewardsum = 0; int32_t i,j,utxovout,scriptlen,numsigs = 0; for (i=0; i proof; for (i=0; i<3; i++) @@ -644,7 +644,11 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) { rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); - fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); + if ( rewards != extradata ) + { + fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); + } + rewardsum += rewards; } if ( skipvalidation == 0 ) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index c38b29598..afe162880 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -146,7 +146,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C return(false); } -std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) +std::string NSPV_signtx(int64_t &rewardsum,int64_t &interestsum,UniValue &retcodes,CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) { CTransaction vintx; std::string hex; uint256 hashBlock; int64_t interest=0,change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n,validation; n = mtx.vout.size(); @@ -158,6 +158,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf totalinputs += used[i].satoshis; interest += used[i].extradata; } + interestsum = interest; if ( (totalinputs+interest) >= totaloutputs+2*txfee ) { change = (totalinputs+interest) - (totaloutputs+txfee); @@ -170,7 +171,7 @@ std::string NSPV_signtx(UniValue &retcodes,CMutableTransaction &mtx,uint64_t txf utxovout = mtx.vin[i].prevout.n; if ( i > 0 ) sleep(1); - validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,used[i].extradata,NSPV_tiptime); + validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,used[i].extradata,NSPV_tiptime,rewardsum); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security { @@ -244,7 +245,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); - std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction tx; + std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction tx; int64_t rewardsum=0,interestsum=0; mtx.fOverwintered = true; mtx.nExpiryHeight = 0; mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; @@ -264,7 +265,12 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a result.push_back(Pair("error","wif expired")); return(result); } - hex = NSPV_signtx(retcodes,mtx,txfee,opret,used); + hex = NSPV_signtx(rewardsum,interestsum,retcodes,mtx,txfee,opret,used); + if ( interestsum != 0 || rewardsum != 0 ) + { + result.push_back(Pair("rewards",dstr(interestsum))); + result.push_back(Pair("validated",dstr(rewardsum))); + } if ( hex.size() > 0 ) { if ( DecodeHexTx(tx,hex) != 0 ) From b46416b3123fa83eadb5ce5d0e3940211a96cecc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:32:59 -1100 Subject: [PATCH 467/659] Test --- src/komodo_nSPV_superlite.h | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index df29e8635..ed3325ade 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -592,33 +592,36 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) { int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) - return(-1); - else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) + { + fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",,ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs); return(-2); - else if ( tx.GetHash() != ptr->nexttxid ) + } + else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) return(-3); - else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) + else if ( tx.GetHash() != ptr->nexttxid ) return(-4); - else if ( height != ptr->common.nextht ) + else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) return(-5); - else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) + else if ( height != ptr->common.nextht ) return(-6); + else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) + return(-7); for (i=ptr->common.numhdrs-1; i>0; i--) { blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) - return(-i-12); + return(-i-13); } if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) - return(-7); - else if ( tx.GetHash() != ptr->prevtxid ) return(-8); - else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) + else if ( tx.GetHash() != ptr->prevtxid ) return(-9); - else if ( height != ptr->common.prevht ) + else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) return(-10); - else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) + else if ( height != ptr->common.prevht ) return(-11); + else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) + return(-12); return(0); } @@ -668,7 +671,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int } if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) { - fprintf(stderr,"gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); + fprintf(stderr,">>>>> gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { From 24f54ef1b6da1a203c524928bf011bd4f2c53de4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:40:19 -1100 Subject: [PATCH 468/659] Test --- src/komodo_nSPV_superlite.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index ed3325ade..f2613def0 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -661,6 +661,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int proof.resize(NSPV_txproofresult.txprooflen); memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); } + fprintf(stderr,"call NSPV_notarizations\n"); NSPV_notarizations(height); // gets the prev and next notarizations if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) { @@ -675,6 +676,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { + fprintf(stderr,"call NSPV_txidhdrsproof\n"); NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { From 47a1d5cbf6edf9354220660123c2511c004e4a3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:42:12 -1100 Subject: [PATCH 469/659] -,, --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index f2613def0..91c55bbd4 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -593,7 +593,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) { - fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",,ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs); + fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs); return(-2); } else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) From 5178ec0d6305c8417ff217e0c1eecd808686bb9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 22:48:22 -1100 Subject: [PATCH 470/659] 5 seconds --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 91c55bbd4..1e5efd049 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -481,7 +481,7 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid); - for (iter=0; iter<3; iter++); + for (iter=0; iter<5; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i Date: Tue, 9 Jul 2019 23:21:38 -1100 Subject: [PATCH 471/659] +print --- src/komodo_nSPV_superlite.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 1e5efd049..b3e584979 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -323,6 +323,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); result.push_back(Pair("lastpeer",NSPV_lastpeer)); + fprintf(stderr,"ntzs_proof %s\n",result); return(result); } @@ -481,7 +482,7 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid); - for (iter=0; iter<5; iter++); + for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i Date: Tue, 9 Jul 2019 23:23:08 -1100 Subject: [PATCH 472/659] .txid.GetHex().c_str() --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index b3e584979..626008694 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -677,7 +677,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { - fprintf(stderr,"call NSPV_txidhdrsproof\n"); + fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str()); NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { From 90be0e94e6d26ceb158027de95ea45301068cdcd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 23:29:02 -1100 Subject: [PATCH 473/659] Pause --- src/komodo_nSPV_superlite.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 626008694..e4c7c3446 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -323,7 +323,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); result.push_back(Pair("lastpeer",NSPV_lastpeer)); - fprintf(stderr,"ntzs_proof %s\n",result); + fprintf(stderr,"ntzs_proof %s %d, %s %d\n",ptr->prevtxid.GetHex().c_str,ptr->common.prevht,ptr->nexttxid.GetHex().c_str,ptr->common.nextht); return(result); } @@ -679,6 +679,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int { fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str()); NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); + usleep(10000); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) { std::vector txids; uint256 proofroot; From 1089c2528203257d7a58c09b11d94c8ae3c5cc60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 23:31:25 -1100 Subject: [PATCH 474/659] () --- src/komodo_nSPV_superlite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index e4c7c3446..f8dd7c9af 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -113,7 +113,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); - LOCK(cs_vNodes); + //LOCK(cs_vNodes); n = 0; BOOST_FOREACH(CNode *ptr,vNodes) { @@ -323,7 +323,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); result.push_back(Pair("lastpeer",NSPV_lastpeer)); - fprintf(stderr,"ntzs_proof %s %d, %s %d\n",ptr->prevtxid.GetHex().c_str,ptr->common.prevht,ptr->nexttxid.GetHex().c_str,ptr->common.nextht); + fprintf(stderr,"ntzs_proof %s %d, %s %d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); return(result); } From cc5e546304d58bbfd4791b20a1f31ed25d72cc9d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 9 Jul 2019 23:47:29 -1100 Subject: [PATCH 475/659] -print --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index f8dd7c9af..90bae8bec 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -323,7 +323,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); result.push_back(Pair("lastpeer",NSPV_lastpeer)); - fprintf(stderr,"ntzs_proof %s %d, %s %d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); + //fprintf(stderr,"ntzs_proof %s %d, %s %d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); return(result); } From f7a7b53bf2cb88060e9a5b47ff8616808f68f886 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 00:09:45 -1100 Subject: [PATCH 476/659] Rearrange --- src/komodo_nSPV_superlite.h | 120 +++--------------------------------- src/komodo_nSPV_wallet.h | 107 ++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 111 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 90bae8bec..8b3d2a762 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -113,7 +113,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); - //LOCK(cs_vNodes); + LOCK(cs_vNodes); n = 0; BOOST_FOREACH(CNode *ptr,vNodes) { @@ -426,6 +426,8 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); + if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag ) + return(NSPV_utxosresp_json(&NSPV_utxosresult)); NSPV_utxosresp_purge(&NSPV_utxosresult); if ( bitcoin_base58decode(msg,coinaddr) != 25 ) { @@ -456,8 +458,8 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) UniValue NSPV_notarizations(int32_t height) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N; - //if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) - // return(NSPV_ntzs_json(&NSPV_ntzsresult)); + if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) + return(NSPV_ntzs_json(&NSPV_ntzsresult)); NSPV_ntzsresp_purge(&NSPV_ntzsresult); msg[len++] = NSPV_NTZS; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); @@ -478,6 +480,8 @@ UniValue NSPV_notarizations(int32_t height) UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsproofresp H; + if ( NSPV_ntzsproofresult.prevtxid == prevtxid && NSPV_ntzsproofresult.nexttxid == nexttxid ) + return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); @@ -509,8 +513,8 @@ UniValue NSPV_hdrsproof(int32_t prevht,int32_t nextht) UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_txproof P; - //if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) - // return(NSPV_txproof_json(&NSPV_txproofresult)); + if ( NSPV_txproofresult.txid == txid ) + return(NSPV_txproof_json(&NSPV_txproofresult)); NSPV_txproof_purge(&NSPV_txproofresult); msg[len++] = NSPV_TXPROOF; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); @@ -589,111 +593,5 @@ UniValue NSPV_broadcast(char *hex) return(NSPV_broadcast_json(&B,txid)); } -int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) -{ - int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; - if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) - { - fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs); - return(-2); - } - else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) - return(-3); - else if ( tx.GetHash() != ptr->nexttxid ) - return(-4); - else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) - return(-5); - else if ( height != ptr->common.nextht ) - return(-6); - else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) - return(-7); - for (i=ptr->common.numhdrs-1; i>0; i--) - { - blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); - if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) - return(-i-13); - } - if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) - return(-8); - else if ( tx.GetHash() != ptr->prevtxid ) - return(-9); - else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) - return(-10); - else if ( height != ptr->common.prevht ) - return(-11); - else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) - return(-12); - return(0); -} - -int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum) -{ - int32_t i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; - for (i=0; i<3; i++) - { - NSPV_txproof(vout,txid,height); - if ( NSPV_txproofresult.txlen != 0 ) - break; - sleep(1); - } - if ( NSPV_txproofresult.txid != txid ) - { - fprintf(stderr,"txproof error %s != %s\n",NSPV_txproofresult.txid.GetHex().c_str(),txid.GetHex().c_str()); - return(-1); - } - else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) - retval = -2000; - else if ( skipvalidation == 0 && NSPV_txproofresult.unspentvalue <= 0 ) - retval = -2001; - else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) - { - rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); - if ( rewards != extradata ) - { - fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); - } - rewardsum += rewards; - } - - if ( skipvalidation == 0 ) - { - if ( NSPV_txproofresult.txprooflen > 0 ) - { - proof.resize(NSPV_txproofresult.txprooflen); - memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); - } - fprintf(stderr,"call NSPV_notarizations\n"); - NSPV_notarizations(height); // gets the prev and next notarizations - if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) - { - fprintf(stderr,"issue manual bracket\n"); - NSPV_notarizations(height-1); - NSPV_notarizations(height+1); - NSPV_notarizations(height); // gets the prev and next notarizations - } - if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) - { - fprintf(stderr,">>>>> gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); - offset = (height - NSPV_ntzsresult.prevntz.height); - if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) - { - fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str()); - NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); - usleep(10000); - if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) - { - std::vector txids; uint256 proofroot; - proofroot = BitcoinGetProofMerkleRoot(proof,txids); - if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) - { - fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",NSPV_txproofresult.txprooflen,proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); - retval = -2003; - } - } - } else retval = -2002; - } else retval = -2004; - } - return(retval); -} #endif // KOMODO_NSPVSUPERLITE_H diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index afe162880..cffdc8381 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -20,6 +20,113 @@ // nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_spend extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); +int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) +{ + int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid; + if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs ) + { + fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs); + return(-2); + } + else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 ) + return(-3); + else if ( tx.GetHash() != ptr->nexttxid ) + return(-4); + else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) + return(-5); + else if ( height != ptr->common.nextht ) + return(-6); + else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash ) + return(-7); + for (i=ptr->common.numhdrs-1; i>0; i--) + { + blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]); + if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) + return(-i-13); + } + if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) + return(-8); + else if ( tx.GetHash() != ptr->prevtxid ) + return(-9); + else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 ) + return(-10); + else if ( height != ptr->common.prevht ) + return(-11); + else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash ) + return(-12); + return(0); +} + +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum) +{ + int32_t i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; + for (i=0; i<3; i++) + { + NSPV_txproof(vout,txid,height); + if ( NSPV_txproofresult.txlen != 0 ) + break; + sleep(1); + } + if ( NSPV_txproofresult.txid != txid ) + { + fprintf(stderr,"txproof error %s != %s\n",NSPV_txproofresult.txid.GetHex().c_str(),txid.GetHex().c_str()); + return(-1); + } + else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) + retval = -2000; + else if ( skipvalidation == 0 && NSPV_txproofresult.unspentvalue <= 0 ) + retval = -2001; + else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) + { + rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); + if ( rewards != extradata ) + { + fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); + } + rewardsum += rewards; + } + + if ( skipvalidation == 0 ) + { + if ( NSPV_txproofresult.txprooflen > 0 ) + { + proof.resize(NSPV_txproofresult.txprooflen); + memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); + } + fprintf(stderr,"call NSPV_notarizations\n"); + NSPV_notarizations(height); // gets the prev and next notarizations + if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) + { + fprintf(stderr,"issue manual bracket\n"); + NSPV_notarizations(height-1); + NSPV_notarizations(height+1); + NSPV_notarizations(height); // gets the prev and next notarizations + } + if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) + { + fprintf(stderr,">>>>> gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height); + offset = (height - NSPV_ntzsresult.prevntz.height); + if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) + { + fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str()); + NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); + usleep(10000); + if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) + { + std::vector txids; uint256 proofroot; + proofroot = BitcoinGetProofMerkleRoot(proof,txids); + if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) + { + fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",NSPV_txproofresult.txprooflen,proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); + retval = -2003; + } + } + } else retval = -2002; + } else retval = -2004; + } + return(retval); +} + int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value) { int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; From 982357098aa3283a632e7075d8861ef450606d8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 00:12:00 -1100 Subject: [PATCH 477/659] Always add rewards validation for KMD --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index cffdc8381..ea25b8983 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -373,7 +373,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } hex = NSPV_signtx(rewardsum,interestsum,retcodes,mtx,txfee,opret,used); - if ( interestsum != 0 || rewardsum != 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { result.push_back(Pair("rewards",dstr(interestsum))); result.push_back(Pair("validated",dstr(rewardsum))); From 879f38c131a9fc1e375d2370e548e064c2550f89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 00:14:25 -1100 Subject: [PATCH 478/659] AmountFromValue --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index ea25b8983..f43c2b424 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -375,8 +375,8 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a hex = NSPV_signtx(rewardsum,interestsum,retcodes,mtx,txfee,opret,used); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - result.push_back(Pair("rewards",dstr(interestsum))); - result.push_back(Pair("validated",dstr(rewardsum))); + result.push_back(Pair("rewards",AmountFromValue(interestsum))); + result.push_back(Pair("validated",AmountFromValue(rewardsum))); } if ( hex.size() > 0 ) { From 2992d085ec626f0c3430715d6413c7953fabc84d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 00:15:33 -1100 Subject: [PATCH 479/659] AmountFromValue --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index ea25b8983..f43c2b424 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -375,8 +375,8 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a hex = NSPV_signtx(rewardsum,interestsum,retcodes,mtx,txfee,opret,used); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - result.push_back(Pair("rewards",dstr(interestsum))); - result.push_back(Pair("validated",dstr(rewardsum))); + result.push_back(Pair("rewards",AmountFromValue(interestsum))); + result.push_back(Pair("validated",AmountFromValue(rewardsum))); } if ( hex.size() > 0 ) { From 958f2c198ef54cbaa7b525d690534f7374bbd08f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 01:21:47 -1100 Subject: [PATCH 480/659] Add caching to three requests: ntzsresp, txproof, ntzsproof --- src/komodo_nSPV.h | 42 +++++++++++++++ src/komodo_nSPV_fullnode.h | 3 +- src/komodo_nSPV_superlite.h | 104 ++++++++++++++++++++++++++++++------ src/komodo_nSPV_wallet.h | 2 - 4 files changed, 131 insertions(+), 20 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 2aec951ba..846e5b879 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -203,6 +203,7 @@ int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) struct NSPV_ntzsresp { struct NSPV_ntz prevntz,nextntz; + int32_t reqheight; }; int32_t NSPV_rwntzsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsresp *ptr) @@ -210,9 +211,15 @@ int32_t NSPV_rwntzsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsresp int32_t len = 0; len += NSPV_rwntz(rwflag,&serialized[len],&ptr->prevntz); len += NSPV_rwntz(rwflag,&serialized[len],&ptr->nextntz); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->reqheight),&ptr->reqheight); return(len); } +void NSPV_ntzsresp_copy(struct NSPV_ntzsresp *dest,struct NSPV_ntzsresp *ptr) +{ + *dest = *ptr; +} + void NSPV_ntzsresp_purge(struct NSPV_ntzsresp *ptr) { if ( ptr != 0 ) @@ -267,6 +274,21 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p return(len); } +void NSPV_txproof_copy(struct NSPV_txproof *dest,struct NSPV_txproof *ptr) +{ + *dest = *ptr; + if ( ptr->tx != 0 ) + { + dest->tx = malloc(ptr->txlen); + memcpy(dest->tx,ptr->tx,ptr->txlen); + } + if ( ptr->txproof != 0 ) + { + dest->txproof = malloc(ptr->txprooflen); + memcpy(dest->txproof,ptr->txproof,ptr->txprooflen); + } +} + void NSPV_txproof_purge(struct NSPV_txproof *ptr) { if ( ptr != 0 ) @@ -321,6 +343,26 @@ int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzs return(len); } +void NSPV_ntzsproof_copy(struct NSPV_ntzsproofresp *dest,struct NSPV_ntzsproofresp *ptr) +{ + *dest = *ptr; + if ( ptr->common.hdrs != 0 ) + { + dest->common.hdrs = malloc(ptr->common.numhdrs * sizeof(*ptr->common.hdrs)); + memcpy(dest->common.hdrs,ptr->common.hdrs,ptr->common.numhdrs * sizeof(*ptr->common.hdrs)); + } + if ( ptr->prevntz != 0 ) + { + dest->prevntz = malloc(ptr->prevtxlen); + memcpy(dest->prevntz,ptr->prevntz,ptr->prevtxlen); + } + if ( ptr->nextntz != 0 ) + { + dest->nextntz = malloc(ptr->nexttxlen); + memcpy(dest->nextntz,ptr->nextntz,ptr->nexttxlen); + } +} + void NSPV_ntzsproofresp_purge(struct NSPV_ntzsproofresp *ptr) { if ( ptr != 0 ) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 0d540e06d..fc56b0a4e 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -77,7 +77,7 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint return(0); } -int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) +int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t reqheight) { struct NSPV_ntzargs prev,next; if ( height < chainActive.LastTip()->GetHeight() ) @@ -86,6 +86,7 @@ int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t height) { if ( prev.ntzheight != 0 ) { + ptr->reqheight = reqheight; if ( NSPV_ntzextract(&ptr->prevntz,prev.txid,prev.txidht,prev.desttxid,prev.ntzheight) < 0 ) return(-1); } diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 8b3d2a762..27fd0d241 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -37,6 +37,72 @@ struct NSPV_ntzsproofresp NSPV_ntzsproofresult; struct NSPV_txproof NSPV_txproofresult; struct NSPV_broadcastresp NSPV_broadcastresult; +struct NSPV_ntzsresp NSPV_ntzsresp_cache[NSPV_MAXVINS]; +struct NSPV_ntzsproofresp NSPV_ntzsproofresp_cache[NSPV_MAXVINS * 2]; +struct NSPV_txproof NSPV_txproof_cache[NSPV_MAXVINS * 4]; + +struct NSPV_ntzsresp *NSPV_ntzsresp_find(int32_t reqheight) +{ + for (i=0; i response) // received a r case NSPV_NTZSRESP: NSPV_ntzsresp_purge(&NSPV_ntzsresult); NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); + if ( NSPV_ntzs_find(NSPV_ntzsresult.reqheight) == 0 ) + NSPV_txproof_add(&NSPV_ntzsresult); fprintf(stderr,"got ntzs response %u size.%d %s prev.%d, %s next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.height); break; case NSPV_NTZSPROOFRESP: NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); NSPV_rwntzsproofresp(0,&response[1],&NSPV_ntzsproofresult); + if ( NSPV_ntzsproof_find(NSPV_ntzsproofresult.prevtxid,NSPV_ntzsproofresult.nexttxid) == 0 ) + NSPV_ntzsproof_add(&NSPV_ntzsproofresult); fprintf(stderr,"got ntzproof response %u size.%d prev.%d next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsproofresult.common.prevht,NSPV_ntzsproofresult.common.nextht); break; case NSPV_TXPROOFRESP: NSPV_txproof_purge(&NSPV_txproofresult); NSPV_rwtxproof(0,&response[1],&NSPV_txproofresult); + if ( NSPV_txproof_find(NSPV_txproofresult.txid) == 0 ) + NSPV_txproof_add(&NSPV_txproofresult); fprintf(stderr,"got txproof response %u size.%d %s ht.%d\n",timestamp,(int32_t)response.size(),NSPV_txproofresult.txid.GetHex().c_str(),NSPV_txproofresult.height); break; case NSPV_SPENTINFORESP: @@ -298,7 +370,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) return(result); } -UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr) +UniValue NSPV_ntzsresp_json(struct NSPV_ntzsresp *ptr) { UniValue result(UniValue::VOBJ); result.push_back(Pair("result","success")); @@ -455,11 +527,11 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) return(result); } -UniValue NSPV_notarizations(int32_t height) +UniValue NSPV_notarizations(int32_t reqheight) { - uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N; - if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) - return(NSPV_ntzs_json(&NSPV_ntzsresult)); + uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N,*ptr; + if ( (ptr= NSPV_ntzsresp_find(reqheight)) != 0 ) + return(NSPV_ntzsresp_json(ptr)); NSPV_ntzsresp_purge(&NSPV_ntzsresult); msg[len++] = NSPV_NTZS; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); @@ -470,18 +542,18 @@ UniValue NSPV_notarizations(int32_t height) { usleep(NSPV_POLLMICROS); if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height ) - return(NSPV_ntzs_json(&NSPV_ntzsresult)); + return(NSPV_ntzsresp_json(&NSPV_ntzsresult)); } } else sleep(1); memset(&N,0,sizeof(N)); - return(NSPV_ntzs_json(&N)); + return(NSPV_ntzsresp_json(&N)); } UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) { - uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsproofresp H; - if ( NSPV_ntzsproofresult.prevtxid == prevtxid && NSPV_ntzsproofresult.nexttxid == nexttxid ) - return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); + uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsproofresp P,*ptr; + if ( (ptr= NSPV_ntzsproof_find(prevtxid,nexttxid)) != 0 ) + return(NSPV_ntzsproof_json(ptr)); NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); @@ -496,8 +568,8 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult)); } } else sleep(1); - memset(&H,0,sizeof(H)); - return(NSPV_ntzsproof_json(&H)); + memset(&P,0,sizeof(P)); + return(NSPV_ntzsproof_json(&P)); } UniValue NSPV_hdrsproof(int32_t prevht,int32_t nextht) @@ -512,9 +584,9 @@ UniValue NSPV_hdrsproof(int32_t prevht,int32_t nextht) UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) { - uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_txproof P; - if ( NSPV_txproofresult.txid == txid ) - return(NSPV_txproof_json(&NSPV_txproofresult)); + uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_txproof P,*ptr; + if ( (ptr= NSPV_txproof_find(txid)) != 0 ) + return(NSPV_txproof_json(ptr)); NSPV_txproof_purge(&NSPV_txproofresult); msg[len++] = NSPV_TXPROOF; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); @@ -539,8 +611,6 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) UniValue NSPV_spentinfo(uint256 txid,int32_t vout) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_spentinfo I; - //if ( NSPV_spentresult.txid == txid && NSPV_spentresult.vout == vout ) - // return(NSPV_spentinfo_json(&NSPV_spentresult)); NSPV_spentinfo_purge(&NSPV_spentresult); msg[len++] = NSPV_SPENTINFO; len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index f43c2b424..bb3d7b86a 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -80,9 +80,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int { rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); if ( rewards != extradata ) - { fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); - } rewardsum += rewards; } From 46b8950f0425e502a6818bf54f2039ae79350fbc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 01:38:55 -1100 Subject: [PATCH 481/659] Syntax --- src/komodo_nSPV.h | 10 +++++----- src/komodo_nSPV_fullnode.h | 6 +++--- src/komodo_nSPV_superlite.h | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 846e5b879..32c9dcd69 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -279,12 +279,12 @@ void NSPV_txproof_copy(struct NSPV_txproof *dest,struct NSPV_txproof *ptr) *dest = *ptr; if ( ptr->tx != 0 ) { - dest->tx = malloc(ptr->txlen); + dest->tx = (uint8_t *)malloc(ptr->txlen); memcpy(dest->tx,ptr->tx,ptr->txlen); } if ( ptr->txproof != 0 ) { - dest->txproof = malloc(ptr->txprooflen); + dest->txproof = (uint8_t *)malloc(ptr->txprooflen); memcpy(dest->txproof,ptr->txproof,ptr->txprooflen); } } @@ -348,17 +348,17 @@ void NSPV_ntzsproof_copy(struct NSPV_ntzsproofresp *dest,struct NSPV_ntzsproofre *dest = *ptr; if ( ptr->common.hdrs != 0 ) { - dest->common.hdrs = malloc(ptr->common.numhdrs * sizeof(*ptr->common.hdrs)); + dest->common.hdrs = (struct NSPV_equihdr *)malloc(ptr->common.numhdrs * sizeof(*ptr->common.hdrs)); memcpy(dest->common.hdrs,ptr->common.hdrs,ptr->common.numhdrs * sizeof(*ptr->common.hdrs)); } if ( ptr->prevntz != 0 ) { - dest->prevntz = malloc(ptr->prevtxlen); + dest->prevntz = (uint8_t *)malloc(ptr->prevtxlen); memcpy(dest->prevntz,ptr->prevntz,ptr->prevtxlen); } if ( ptr->nextntz != 0 ) { - dest->nextntz = malloc(ptr->nexttxlen); + dest->nextntz = (uint8_t *)malloc(ptr->nexttxlen); memcpy(dest->nextntz,ptr->nextntz,ptr->nexttxlen); } } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index fc56b0a4e..629abfb17 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -80,9 +80,9 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t reqheight) { struct NSPV_ntzargs prev,next; - if ( height < chainActive.LastTip()->GetHeight() ) - height++; - if ( NSPV_notarized_bracket(&prev,&next,height) == 0 ) + if ( reqheight < chainActive.LastTip()->GetHeight() ) + reqheight++; + if ( NSPV_notarized_bracket(&prev,&next,reqheight) == 0 ) { if ( prev.ntzheight != 0 ) { diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 27fd0d241..3d3c5ef26 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -43,6 +43,7 @@ struct NSPV_txproof NSPV_txproof_cache[NSPV_MAXVINS * 4]; struct NSPV_ntzsresp *NSPV_ntzsresp_find(int32_t reqheight) { + int32_t i; for (i=0; i Date: Wed, 10 Jul 2019 01:40:26 -1100 Subject: [PATCH 482/659] Syntax --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 3d3c5ef26..90b8f4523 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -50,7 +50,7 @@ struct NSPV_ntzsresp *NSPV_ntzsresp_find(int32_t reqheight) return(0); } -struct NSPV_txproof *NSPV_ntzsresp_add(struct NSPV_ntzsresp *ptr) +struct NSPV_ntzsresp *NSPV_ntzsresp_add(struct NSPV_ntzsresp *ptr) { int32_t i; for (i=0; i response) // received a r case NSPV_NTZSRESP: NSPV_ntzsresp_purge(&NSPV_ntzsresult); NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); - if ( NSPV_ntzs_find(NSPV_ntzsresult.reqheight) == 0 ) - NSPV_txproof_add(&NSPV_ntzsresult); + if ( NSPV_ntzsresp_find(NSPV_ntzsresult.reqheight) == 0 ) + NSPV_ntzsresp_add(&NSPV_ntzsresult); fprintf(stderr,"got ntzs response %u size.%d %s prev.%d, %s next.%d\n",timestamp,(int32_t)response.size(),NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.height); break; case NSPV_NTZSPROOFRESP: From 2584080a31dd6d0f26703c821cac22edc4b1b96b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 01:42:16 -1100 Subject: [PATCH 483/659] Syntax --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 90b8f4523..37157fd64 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -98,11 +98,11 @@ struct NSPV_ntzsproofresp *NSPV_ntzsproof_add(struct NSPV_ntzsproofresp *ptr) { int32_t i; for (i=0; i>1) != 0 ) { From ef096457b5ca837e1f121d0996c4bbecb51d5245 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 01:44:04 -1100 Subject: [PATCH 484/659] Reqheight --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 37157fd64..73ff1260f 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -544,7 +544,7 @@ UniValue NSPV_notarizations(int32_t reqheight) for (i=0; i= height ) + if ( NSPV_ntzsresult.prevntz.reqheight == reqheight ) return(NSPV_ntzsresp_json(&NSPV_ntzsresult)); } } else sleep(1); From adde9f27412372a75fbc72e4d7de678397eed738 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 01:45:03 -1100 Subject: [PATCH 485/659] Req --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 73ff1260f..caf1178c1 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -544,7 +544,7 @@ UniValue NSPV_notarizations(int32_t reqheight) for (i=0; i Date: Wed, 10 Jul 2019 01:51:58 -1100 Subject: [PATCH 486/659] +print --- src/komodo_nSPV_superlite.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index caf1178c1..5893429e9 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -60,6 +60,7 @@ struct NSPV_ntzsresp *NSPV_ntzsresp_add(struct NSPV_ntzsresp *ptr) i == (rand() % (sizeof(NSPV_ntzsresp_cache)/sizeof(*NSPV_ntzsresp_cache))); NSPV_ntzsresp_purge(&NSPV_ntzsresp_cache[i]); NSPV_ntzsresp_copy(&NSPV_ntzsresp_cache[i],ptr); + fprintf(stderr,"ADD CACHE ntzsresp req.%d\n",ptr->reqheight); return(&NSPV_ntzsresp_cache[i]); } @@ -82,6 +83,7 @@ struct NSPV_txproof *NSPV_txproof_add(struct NSPV_txproof *ptr) i == (rand() % (sizeof(NSPV_txproof_cache)/sizeof(*NSPV_txproof_cache))); NSPV_txproof_purge(&NSPV_txproof_cache[i]); NSPV_txproof_copy(&NSPV_txproof_cache[i],ptr); + fprintf(stderr,"ADD CACHE txproof %s\n",ptr->txid.GetHex().c_str()); return(&NSPV_txproof_cache[i]); } @@ -104,6 +106,7 @@ struct NSPV_ntzsproofresp *NSPV_ntzsproof_add(struct NSPV_ntzsproofresp *ptr) i == (rand() % (sizeof(NSPV_ntzsproofresp_cache)/sizeof(*NSPV_ntzsproofresp_cache))); NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresp_cache[i]); NSPV_ntzsproof_copy(&NSPV_ntzsproofresp_cache[i],ptr); + fprintf(stderr,"ADD CACHE ntzsproof %s %s\n",ptr->prevtxid.GetHex().c_str(),ptr->nexttxid.GetHex().c_str()); return(&NSPV_ntzsproofresp_cache[i]); } @@ -534,7 +537,10 @@ UniValue NSPV_notarizations(int32_t reqheight) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N,*ptr; if ( (ptr= NSPV_ntzsresp_find(reqheight)) != 0 ) + { + fprintf(stderr,"FROM CACHE NSPV_notarizations.%d\n",reqheight); return(NSPV_ntzsresp_json(ptr)); + } NSPV_ntzsresp_purge(&NSPV_ntzsresult); msg[len++] = NSPV_NTZS; len += iguana_rwnum(1,&msg[len],sizeof(reqheight),&reqheight); @@ -556,7 +562,10 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsproofresp P,*ptr; if ( (ptr= NSPV_ntzsproof_find(prevtxid,nexttxid)) != 0 ) + { + fprintf(stderr,"FROM CACHE NSPV_txidhdrsproof %s %s\n",ptr->prevtxid.GetHex().c_str(),ptr->nexttxid.GetHex().c_str()); return(NSPV_ntzsproof_json(ptr)); + } NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); @@ -589,7 +598,10 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_txproof P,*ptr; if ( (ptr= NSPV_txproof_find(txid)) != 0 ) + { + fprintf(stderr,"FROM CACHE NSPV_txproof %s %s\n",txid.GetHex().c_str()); return(NSPV_txproof_json(ptr)); + } NSPV_txproof_purge(&NSPV_txproofresult); msg[len++] = NSPV_TXPROOF; len += iguana_rwnum(1,&msg[len],sizeof(height),&height); From 80a2d6431fffceaf9bf8739dfa83d8f417d77abb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 01:52:35 -1100 Subject: [PATCH 487/659] -sleep --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 32c9dcd69..e175b40c3 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -561,7 +561,7 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4 ) { - sleep(1); + //sleep(1); *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); nTime = NSPV_blocktime(*ntzheightp); komodo_notaries(elected,*ntzheightp,nTime); From 12084bf9ab9bb1334d51cf1b54e00f3dc4e48796 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 01:56:38 -1100 Subject: [PATCH 488/659] - %s --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 5893429e9..b9acd4791 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -599,7 +599,7 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_txproof P,*ptr; if ( (ptr= NSPV_txproof_find(txid)) != 0 ) { - fprintf(stderr,"FROM CACHE NSPV_txproof %s %s\n",txid.GetHex().c_str()); + fprintf(stderr,"FROM CACHE NSPV_txproof %s\n",txid.GetHex().c_str()); return(NSPV_txproof_json(ptr)); } NSPV_txproof_purge(&NSPV_txproofresult); From cbed35aa1c17856ff19e97475c32b9288bea561e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 02:02:19 -1100 Subject: [PATCH 489/659] Origreqheight --- src/komodo_nSPV_fullnode.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 629abfb17..bbc1712b8 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -77,16 +77,16 @@ int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint return(0); } -int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t reqheight) +int32_t NSPV_getntzsresp(struct NSPV_ntzsresp *ptr,int32_t origreqheight) { - struct NSPV_ntzargs prev,next; + struct NSPV_ntzargs prev,next; int32_t reqheight = origreqheight; if ( reqheight < chainActive.LastTip()->GetHeight() ) reqheight++; if ( NSPV_notarized_bracket(&prev,&next,reqheight) == 0 ) { if ( prev.ntzheight != 0 ) { - ptr->reqheight = reqheight; + ptr->reqheight = origreqheight; if ( NSPV_ntzextract(&ptr->prevntz,prev.txid,prev.txidht,prev.desttxid,prev.ntzheight) < 0 ) return(-1); } From 0fbb1df96b2665d648c78f5c48633f28549635d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 02:03:28 -1100 Subject: [PATCH 490/659] Test --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index b9acd4791..ca599e56a 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -215,7 +215,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - if ( KOMODO_NSPV == 0 ) + if ( KOMODO_NSPV != 0 ) fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; From 9963d63159511f7b605f3d9f05b6c2cf5ebf76ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 02:11:23 -1100 Subject: [PATCH 491/659] Txproof --- src/komodo_nSPV_superlite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index ca599e56a..17e1f3053 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -607,7 +607,7 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); - //fprintf(stderr,"req txproof %s/v%d at height.%d\n",txid.GetHex().c_str(),vout,height); + fprintf(stderr,"req txproof %s/v%d at height.%d\n",txid.GetHex().c_str(),vout,height); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { @@ -618,7 +618,7 @@ UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height) return(NSPV_txproof_json(&NSPV_txproofresult)); } } else sleep(1); - //fprintf(stderr,"txproof timeout\n"); + fprintf(stderr,"txproof timeout\n"); memset(&P,0,sizeof(P)); return(NSPV_txproof_json(&P)); } From 07e4f28dc94f3ee5dfdecfb6fe66e9b0afa5ea67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 02:22:37 -1100 Subject: [PATCH 492/659] Fix code flow --- src/komodo_nSPV_superlite.h | 14 +++++++++++--- src/komodo_nSPV_wallet.h | 27 ++++++++++++--------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 17e1f3053..383cd025b 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -231,6 +231,9 @@ UniValue NSPV_logout() if ( NSPV_logintime != 0 ) fprintf(stderr,"scrub wif and privkey from NSPV memory\n"); else result.push_back(Pair("status","wasnt logged in")); + memset(NSPV_ntzsproofresp_cache,0,sizeof(NSPV_ntzsproofresp_cache)); + memset(NSPV_txproof_cache,0,sizeof(NSPV_txproof_cache)); + memset(NSPV_ntzsresp_cache,0,sizeof(NSPV_ntzsresp_cache)); memset(NSPV_wifstr,0,sizeof(NSPV_wifstr)); memset(&NSPV_key,0,sizeof(NSPV_key)); NSPV_logintime = 0; @@ -539,9 +542,10 @@ UniValue NSPV_notarizations(int32_t reqheight) if ( (ptr= NSPV_ntzsresp_find(reqheight)) != 0 ) { fprintf(stderr,"FROM CACHE NSPV_notarizations.%d\n",reqheight); + NSPV_ntzsresp_purge(&NSPV_ntzsresult); + NSPV_ntzsresp_copy(&NSPV_ntzsresult,ptr); return(NSPV_ntzsresp_json(ptr)); } - NSPV_ntzsresp_purge(&NSPV_ntzsresult); msg[len++] = NSPV_NTZS; len += iguana_rwnum(1,&msg[len],sizeof(reqheight),&reqheight); for (iter=0; iter<3; iter++); @@ -564,13 +568,15 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) if ( (ptr= NSPV_ntzsproof_find(prevtxid,nexttxid)) != 0 ) { fprintf(stderr,"FROM CACHE NSPV_txidhdrsproof %s %s\n",ptr->prevtxid.GetHex().c_str(),ptr->nexttxid.GetHex().c_str()); + NSPV_txidhdrsproof_purge(&NSPV_ntzsproofresult); + NSPV_txidhdrsproof_copy(&NSPV_ntzsproofresult,ptr); return(NSPV_ntzsproof_json(ptr)); } NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid); - for (iter=0; iter<3; iter++); + //for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i proof; - for (i=0; i<3; i++) + struct NSPV_txproof *ptr; int32_t i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; + if ( (ptr= NSPV_txproof_find(txid)) == 0 ) { NSPV_txproof(vout,txid,height); - if ( NSPV_txproofresult.txlen != 0 ) - break; - sleep(1); + ptr = &NSPV_txproofresult; } - if ( NSPV_txproofresult.txid != txid ) + if ( ptr->txid != txid ) { - fprintf(stderr,"txproof error %s != %s\n",NSPV_txproofresult.txid.GetHex().c_str(),txid.GetHex().c_str()); + fprintf(stderr,"txproof error %s != %s\n",ptr->txid.GetHex().c_str(),txid.GetHex().c_str()); return(-1); } - else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 ) + else if ( NSPV_txextract(tx,ptr->tx,ptr->txlen) < 0 || ptr->txlen <= 0 ) retval = -2000; - else if ( skipvalidation == 0 && NSPV_txproofresult.unspentvalue <= 0 ) + else if ( skipvalidation == 0 && ptr->unspentvalue <= 0 ) retval = -2001; else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) { @@ -86,12 +84,11 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int if ( skipvalidation == 0 ) { - if ( NSPV_txproofresult.txprooflen > 0 ) + if ( ptr->txprooflen > 0 ) { - proof.resize(NSPV_txproofresult.txprooflen); - memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen); + proof.resize(ptr->txprooflen); + memcpy(&proof[0],ptr->txproof,ptr->txprooflen); } - fprintf(stderr,"call NSPV_notarizations\n"); NSPV_notarizations(height); // gets the prev and next notarizations if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) ) { @@ -106,7 +103,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int offset = (height - NSPV_ntzsresult.prevntz.height); if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height ) { - fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str()); + //fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str()); NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid); usleep(10000); if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 ) @@ -115,7 +112,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int proofroot = BitcoinGetProofMerkleRoot(proof,txids); if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) { - fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",NSPV_txproofresult.txprooflen,proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); + fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",(int32_t)proof.size(),proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); retval = -2003; } } From 10a7cb5f44407ee9eb84b1c0a5042e23315998b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 02:25:36 -1100 Subject: [PATCH 493/659] Syntax --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_superlite.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e175b40c3..c623e15d1 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -343,7 +343,7 @@ int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzs return(len); } -void NSPV_ntzsproof_copy(struct NSPV_ntzsproofresp *dest,struct NSPV_ntzsproofresp *ptr) +void NSPV_ntzsproofresp_copy(struct NSPV_ntzsproofresp *dest,struct NSPV_ntzsproofresp *ptr) { *dest = *ptr; if ( ptr->common.hdrs != 0 ) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 383cd025b..b31115079 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -105,7 +105,7 @@ struct NSPV_ntzsproofresp *NSPV_ntzsproof_add(struct NSPV_ntzsproofresp *ptr) if ( i == sizeof(NSPV_ntzsproofresp_cache)/sizeof(*NSPV_ntzsproofresp_cache) ) i == (rand() % (sizeof(NSPV_ntzsproofresp_cache)/sizeof(*NSPV_ntzsproofresp_cache))); NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresp_cache[i]); - NSPV_ntzsproof_copy(&NSPV_ntzsproofresp_cache[i],ptr); + NSPV_ntzsproofresp_copy(&NSPV_ntzsproofresp_cache[i],ptr); fprintf(stderr,"ADD CACHE ntzsproof %s %s\n",ptr->prevtxid.GetHex().c_str(),ptr->nexttxid.GetHex().c_str()); return(&NSPV_ntzsproofresp_cache[i]); } @@ -215,7 +215,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) std::vector request; request.resize(len); memcpy(&request[0],msg,len); - if ( KOMODO_NSPV != 0 ) + if ( (0) && KOMODO_NSPV != 0 ) fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len); pnode->PushMessage("getnSPV",request); pnode->prevtimes[ind] = timestamp; @@ -568,8 +568,8 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) if ( (ptr= NSPV_ntzsproof_find(prevtxid,nexttxid)) != 0 ) { fprintf(stderr,"FROM CACHE NSPV_txidhdrsproof %s %s\n",ptr->prevtxid.GetHex().c_str(),ptr->nexttxid.GetHex().c_str()); - NSPV_txidhdrsproof_purge(&NSPV_ntzsproofresult); - NSPV_txidhdrsproof_copy(&NSPV_ntzsproofresult,ptr); + NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); + NSPV_ntzsproofresp_copy(&NSPV_ntzsproofresult,ptr); return(NSPV_ntzsproof_json(ptr)); } NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult); From 359aaf0c8143fc081ba95937268e8eb6ad121858 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 02:29:59 -1100 Subject: [PATCH 494/659] Add delay --- src/komodo_nSPV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c623e15d1..aacc0a583 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -561,7 +561,7 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4 ) { - //sleep(1); + sleep(1); // needed to avoid no pnodes error *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); nTime = NSPV_blocktime(*ntzheightp); komodo_notaries(elected,*ntzheightp,nTime); From 15eb217c46f8294007cdd95f1ef514b1653698fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 02:32:13 -1100 Subject: [PATCH 495/659] Tweak sleeps --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_wallet.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index aacc0a583..c8338d365 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -561,7 +561,7 @@ int32_t NSPV_notarizationextract(int32_t verifyntz,int32_t *ntzheightp,uint256 * GetOpReturnData(tx.vout[1].scriptPubKey,opret); if ( opret.size() >= 32*2+4 ) { - sleep(1); // needed to avoid no pnodes error + //sleep(1); // needed to avoid no pnodes error *desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash()); nTime = NSPV_blocktime(*ntzheightp); komodo_notaries(elected,*ntzheightp,nTime); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index cf409aa61..300d5de22 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -44,6 +44,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) return(-i-13); } + sleep(1); if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) return(-8); else if ( tx.GetHash() != ptr->prevtxid ) From 95dcb9cd326a1754548a43b63f58aa7accc6a5b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 03:46:40 -1100 Subject: [PATCH 496/659] Initial CC support skeleton --- src/cc/CCinclude.h | 5 +- src/cc/CCtx.cpp | 8 +- src/komodo_nSPV.h | 129 ----------------------------- src/komodo_nSPV_defs.h | 156 ++++++++++++++++++++++++++++++++++++ src/komodo_nSPV_superlite.h | 1 - src/komodo_nSPV_wallet.h | 9 +++ src/main.cpp | 1 + 7 files changed, 172 insertions(+), 137 deletions(-) create mode 100644 src/komodo_nSPV_defs.h diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 4c6791676..c485ffb2d 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -52,6 +52,7 @@ one other technical note is that komodod has the insight-explorer extensions bui #include "../utlist.h" #include "../uthash.h" #include "merkleblock.h" +#include "../komodo_nSPV_defs.h" #define CC_BURNPUBKEY "02deaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead" #define CC_MAXVINS 1024 @@ -287,8 +288,8 @@ extern std::vector NULL_pubkeys; std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool CCflag = true); void SetCCtxids(std::vector > &addressIndex,char *coinaddr,bool CCflag = true); -int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); -int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs); +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr = 0); +int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr = 0); int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag); bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 3931e19b4..e6da6a46b 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -518,13 +518,11 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * else return(belowi); } -int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr) { - int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxosinfo *utxos,*up; if ( KOMODO_NSPV != 0 ) - { - //return(NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t num)); - } + return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr)); #ifdef ENABLE_WALLET assert(pwalletMain != NULL); const CKeyStore& keystore = *pwalletMain; diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c8338d365..f0e59e8cb 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -28,33 +28,6 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -#define NSPV_POLLITERS 15 -#define NSPV_POLLMICROS 100000 -#define NSPV_MAXVINS 64 -#define NSPV_AUTOLOGOUT 777 -#define NSPV_BRANCHID 0x76b809bb - -// nSPV defines and struct definitions with serialization and purge functions - -#define NSPV_INFO 0x00 -#define NSPV_INFORESP 0x01 -#define NSPV_UTXOS 0x02 -#define NSPV_UTXOSRESP 0x03 -#define NSPV_NTZS 0x04 -#define NSPV_NTZSRESP 0x05 -#define NSPV_NTZSPROOF 0x06 -#define NSPV_NTZSPROOFRESP 0x07 -#define NSPV_TXPROOF 0x08 -#define NSPV_TXPROOFRESP 0x09 -#define NSPV_SPENTINFO 0x0a -#define NSPV_SPENTINFORESP 0x0b -#define NSPV_BROADCAST 0x0c -#define NSPV_BROADCASTRESP 0x0d - -int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum); -extern uint256 SIG_TXHASH; -uint32_t NSPV_blocktime(int32_t hdrheight); - int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf) { if ( rwflag != 0 ) @@ -63,18 +36,6 @@ int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *bu return(len); } -struct NSPV_equihdr -{ - int32_t nVersion; - uint256 hashPrevBlock; - uint256 hashMerkleRoot; - uint256 hashFinalSaplingRoot; - uint32_t nTime; - uint32_t nBits; - uint256 nNonce; - uint8_t nSolution[1344]; -}; - int32_t NSPV_rwequihdr(int32_t rwflag,uint8_t *serialized,struct NSPV_equihdr *ptr) { int32_t len = 0; @@ -117,13 +78,6 @@ int32_t iguana_rwuint8vec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsizep, return(len); } -struct NSPV_utxoresp -{ - uint256 txid; - int64_t satoshis,extradata; - int32_t vout,height; -}; - int32_t NSPV_rwutxoresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxoresp *ptr) { int32_t len = 0; @@ -135,15 +89,6 @@ int32_t NSPV_rwutxoresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxoresp return(len); } -struct NSPV_utxosresp -{ - struct NSPV_utxoresp *utxos; - char coinaddr[64]; - int64_t total,interest; - int32_t nodeheight; - uint16_t numutxos; uint8_t CCflag,pad8; -}; - int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosresp *ptr) // check mempool { int32_t i,len = 0; @@ -173,22 +118,6 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres return(len); } -void NSPV_utxosresp_purge(struct NSPV_utxosresp *ptr) -{ - if ( ptr != 0 ) - { - if ( ptr->utxos != 0 ) - free(ptr->utxos); - memset(ptr,0,sizeof(*ptr)); - } -} - -struct NSPV_ntz -{ - uint256 blockhash,txid,othertxid; - int32_t height,txidheight; -}; - int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) { int32_t len = 0; @@ -200,12 +129,6 @@ int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) return(len); } -struct NSPV_ntzsresp -{ - struct NSPV_ntz prevntz,nextntz; - int32_t reqheight; -}; - int32_t NSPV_rwntzsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsresp *ptr) { int32_t len = 0; @@ -226,14 +149,6 @@ void NSPV_ntzsresp_purge(struct NSPV_ntzsresp *ptr) memset(ptr,0,sizeof(*ptr)); } -struct NSPV_inforesp -{ - struct NSPV_ntz notarization; - uint256 blockhash; - int32_t height,hdrheight; - struct NSPV_equihdr H; -}; - int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp *ptr) { int32_t len = 0; @@ -252,15 +167,6 @@ void NSPV_inforesp_purge(struct NSPV_inforesp *ptr) memset(ptr,0,sizeof(*ptr)); } -struct NSPV_txproof -{ - uint256 txid; - int64_t unspentvalue; - int32_t height,vout,pad; - uint16_t txlen,txprooflen; - uint8_t *tx,*txproof; -}; - int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *ptr) { int32_t len = 0; @@ -301,13 +207,6 @@ void NSPV_txproof_purge(struct NSPV_txproof *ptr) } } -struct NSPV_ntzproofshared -{ - struct NSPV_equihdr *hdrs; - int32_t prevht,nextht,pad32; - uint16_t numhdrs,pad16; -}; - int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzproofshared *ptr) { int32_t len = 0; @@ -320,15 +219,6 @@ int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz return(len); } -struct NSPV_ntzsproofresp -{ - struct NSPV_ntzproofshared common; - uint256 prevtxid,nexttxid; - int32_t pad32,prevtxidht,nexttxidht; - uint16_t prevtxlen,nexttxlen; - uint8_t *prevntz,*nextntz; -}; - int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsproofresp *ptr) { int32_t len = 0; @@ -377,19 +267,6 @@ void NSPV_ntzsproofresp_purge(struct NSPV_ntzsproofresp *ptr) } } -struct NSPV_MMRproof -{ - struct NSPV_ntzproofshared common; - // tbd -}; - -struct NSPV_spentinfo -{ - struct NSPV_txproof spent; - uint256 txid; - int32_t vout,spentvini; -}; - int32_t NSPV_rwspentinfo(int32_t rwflag,uint8_t *serialized,struct NSPV_spentinfo *ptr) // check mempool { int32_t len = 0; @@ -409,12 +286,6 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) } } -struct NSPV_broadcastresp -{ - uint256 txid; - int32_t retcode; -}; - int32_t NSPV_rwbroadcastresp(int32_t rwflag,uint8_t *serialized,struct NSPV_broadcastresp *ptr) { int32_t len = 0; diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h new file mode 100644 index 000000000..d0c649ce5 --- /dev/null +++ b/src/komodo_nSPV_defs.h @@ -0,0 +1,156 @@ + +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +// todo: + +// headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs + +// interest calculations are currently just using what is returned, it should calculate it from scratch + +// CC signing +// make sure to sanity check all vector lengths on receipt +// make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) +// bug: under load, fullnode was returning all 0 nServices + +#ifndef KOMODO_NSPV_DEFSH +#define KOMODO_NSPV_DEFSH + +#define NSPV_POLLITERS 15 +#define NSPV_POLLMICROS 100000 +#define NSPV_MAXVINS 64 +#define NSPV_AUTOLOGOUT 777 +#define NSPV_BRANCHID 0x76b809bb + +// nSPV defines and struct definitions with serialization and purge functions + +#define NSPV_INFO 0x00 +#define NSPV_INFORESP 0x01 +#define NSPV_UTXOS 0x02 +#define NSPV_UTXOSRESP 0x03 +#define NSPV_NTZS 0x04 +#define NSPV_NTZSRESP 0x05 +#define NSPV_NTZSPROOF 0x06 +#define NSPV_NTZSPROOFRESP 0x07 +#define NSPV_TXPROOF 0x08 +#define NSPV_TXPROOFRESP 0x09 +#define NSPV_SPENTINFO 0x0a +#define NSPV_SPENTINFORESP 0x0b +#define NSPV_BROADCAST 0x0c +#define NSPV_BROADCASTRESP 0x0d + +int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum); +extern uint256 SIG_TXHASH; +uint32_t NSPV_blocktime(int32_t hdrheight); + +struct NSPV_equihdr +{ + int32_t nVersion; + uint256 hashPrevBlock; + uint256 hashMerkleRoot; + uint256 hashFinalSaplingRoot; + uint32_t nTime; + uint32_t nBits; + uint256 nNonce; + uint8_t nSolution[1344]; +}; + +struct NSPV_utxoresp +{ + uint256 txid; + int64_t satoshis,extradata; + int32_t vout,height; +}; + +struct NSPV_utxosresp +{ + struct NSPV_utxoresp *utxos; + char coinaddr[64]; + int64_t total,interest; + int32_t nodeheight; + uint16_t numutxos; uint8_t CCflag,pad8; +}; + +struct NSPV_ntz +{ + uint256 blockhash,txid,othertxid; + int32_t height,txidheight; +}; + +struct NSPV_ntzsresp +{ + struct NSPV_ntz prevntz,nextntz; + int32_t reqheight; +}; + +struct NSPV_inforesp +{ + struct NSPV_ntz notarization; + uint256 blockhash; + int32_t height,hdrheight; + struct NSPV_equihdr H; +}; + +struct NSPV_txproof +{ + uint256 txid; + int64_t unspentvalue; + int32_t height,vout,pad; + uint16_t txlen,txprooflen; + uint8_t *tx,*txproof; +}; + +struct NSPV_ntzproofshared +{ + struct NSPV_equihdr *hdrs; + int32_t prevht,nextht,pad32; + uint16_t numhdrs,pad16; +}; + +struct NSPV_ntzsproofresp +{ + struct NSPV_ntzproofshared common; + uint256 prevtxid,nexttxid; + int32_t pad32,prevtxidht,nexttxidht; + uint16_t prevtxlen,nexttxlen; + uint8_t *prevntz,*nextntz; +}; + +struct NSPV_MMRproof +{ + struct NSPV_ntzproofshared common; + // tbd +}; + +struct NSPV_spentinfo +{ + struct NSPV_txproof spent; + uint256 txid; + int32_t vout,spentvini; +}; + +struct NSPV_broadcastresp +{ + uint256 txid; + int32_t retcode; +}; + +struct CC_utxosinfo +{ + struct NSPV_utxosresp U; + struct NSPV_utxoresp used[NSPV_MAXVINS]; +}; + +#endif // KOMODO_NSPV_DEFSH diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index b31115079..7c5039b78 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -686,5 +686,4 @@ UniValue NSPV_broadcast(char *hex) return(NSPV_broadcast_json(&B,txid)); } - #endif // KOMODO_NSPVSUPERLITE_H diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 300d5de22..dac7b9e49 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -406,4 +406,13 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a } } +int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr) +{ + if ( ptr != 0 ) + { + memset(ptr->used,0,sizeof(ptr->used)); + return(NSPV_addinputs(ptr->used,mtx,total,maxinputs,ptr->U.utxos,ptr->U.numutxos)); + } else return(0); +} + #endif // KOMODO_NSPVWALLET_H diff --git a/src/main.cpp b/src/main.cpp index a8ff33c2b..ab8b27ba5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7060,6 +7060,7 @@ void static ProcessGetData(CNode* pfrom) } } +#include "komodo_nSPV_defs.h" #include "komodo_nSPV.h" // shared defines, structs, serdes, purge functions #include "komodo_nSPV_fullnode.h" // nSPV fullnode handling of the getnSPV request messages #include "komodo_nSPV_superlite.h" // nSPV superlite client, issuing requests and handling nSPV responses From ee2ec523178b4541a7818e63dc1833980b93c1e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 03:50:45 -1100 Subject: [PATCH 497/659] Test --- src/cc/CCinclude.h | 1 + src/cc/CCtx.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index c485ffb2d..b51b71323 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -288,6 +288,7 @@ extern std::vector NULL_pubkeys; std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool CCflag = true); void SetCCtxids(std::vector > &addressIndex,char *coinaddr,bool CCflag = true); +int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr = 0); int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr = 0); int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index e6da6a46b..a8adab849 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -528,7 +528,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); - utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos)); + utxos = (struct CC_utxosinfo *)calloc(CC_MAXVINS,sizeof(*utxos)); if ( maxinputs > CC_MAXVINS ) maxinputs = CC_MAXVINS; if ( maxinputs > 0 ) From 2530a6b8920334824123493ac2120f54ae011ae1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 03:54:23 -1100 Subject: [PATCH 498/659] Test --- src/cc/CCinclude.h | 6 +++--- src/cc/CCtx.cpp | 2 +- src/komodo_nSPV_defs.h | 2 +- src/komodo_nSPV_wallet.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index b51b71323..ae5791358 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -288,9 +288,9 @@ extern std::vector NULL_pubkeys; std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool CCflag = true); void SetCCtxids(std::vector > &addressIndex,char *coinaddr,bool CCflag = true); -int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr); -int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr = 0); -int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr = 0); +int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr); +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr = 0); +int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr = 0); int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag); bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index a8adab849..39f6e49ef 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -518,7 +518,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * else return(belowi); } -int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr) +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxosinfo *utxos,*up; if ( KOMODO_NSPV != 0 ) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index d0c649ce5..d0dca2543 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -147,7 +147,7 @@ struct NSPV_broadcastresp int32_t retcode; }; -struct CC_utxosinfo +struct NSPV_CCutxosinfo { struct NSPV_utxosresp U; struct NSPV_utxoresp used[NSPV_MAXVINS]; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index dac7b9e49..892ed0991 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -406,7 +406,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a } } -int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr) +int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr) { if ( ptr != 0 ) { From bf173b7158b602a7af7ff171eb89283ff35f5138 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 03:58:57 -1100 Subject: [PATCH 499/659] NSPV_CCmtxinfo --- src/cc/CCinclude.h | 6 +++--- src/cc/CCtx.cpp | 2 +- src/komodo_nSPV_defs.h | 2 +- src/komodo_nSPV_wallet.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index ae5791358..4fb5bfbe5 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -288,9 +288,9 @@ extern std::vector NULL_pubkeys; std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool CCflag = true); void SetCCtxids(std::vector > &addressIndex,char *coinaddr,bool CCflag = true); -int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr); -int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr = 0); -int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr = 0); +int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr); +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr = 0); +int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr = 0); int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag); bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 39f6e49ef..6c0f2e8d0 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -518,7 +518,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * else return(belowi); } -int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr) +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxosinfo *utxos,*up; if ( KOMODO_NSPV != 0 ) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index d0dca2543..c1ec60817 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -147,7 +147,7 @@ struct NSPV_broadcastresp int32_t retcode; }; -struct NSPV_CCutxosinfo +struct NSPV_CCmtxinfo { struct NSPV_utxosresp U; struct NSPV_utxoresp used[NSPV_MAXVINS]; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 892ed0991..cb2e6ea79 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -406,7 +406,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a } } -int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCutxosinfo *ptr) +int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr) { if ( ptr != 0 ) { From 81dc3e8b836f2fe9b5ab7f085a3507b5c4063eac Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 04:02:04 -1100 Subject: [PATCH 500/659] CC_utxo --- src/cc/CCtx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 6c0f2e8d0..005a06380 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -520,7 +520,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr) { - int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxosinfo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; if ( KOMODO_NSPV != 0 ) return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr)); #ifdef ENABLE_WALLET @@ -528,7 +528,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); - utxos = (struct CC_utxosinfo *)calloc(CC_MAXVINS,sizeof(*utxos)); + utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos)); if ( maxinputs > CC_MAXVINS ) maxinputs = CC_MAXVINS; if ( maxinputs > 0 ) From b444625676b857a6b9fe5dc7f5d5273f988b3390 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 04:20:03 -1100 Subject: [PATCH 501/659] Restore NSPV_utxosresp_purge --- src/komodo_nSPV.h | 14 ++++++++++++-- src/komodo_nSPV_defs.h | 11 ----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index f0e59e8cb..9c577512d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -16,11 +16,11 @@ // todo: +// CC signing + // headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs -// interest calculations are currently just using what is returned, it should calculate it from scratch -// CC signing // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) // bug: under load, fullnode was returning all 0 nServices @@ -118,6 +118,16 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres return(len); } +void NSPV_utxosresp_purge(struct NSPV_utxosresp *ptr) +{ + if ( ptr != 0 ) + { + if ( ptr->utxos != 0 ) + free(ptr->utxos); + memset(ptr,0,sizeof(*ptr)); + } +} + int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) { int32_t len = 0; diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index c1ec60817..537a7209e 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -14,17 +14,6 @@ * * ******************************************************************************/ -// todo: - -// headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs - -// interest calculations are currently just using what is returned, it should calculate it from scratch - -// CC signing -// make sure to sanity check all vector lengths on receipt -// make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) -// bug: under load, fullnode was returning all 0 nServices - #ifndef KOMODO_NSPV_DEFSH #define KOMODO_NSPV_DEFSH From c3e7c38dfd1b4f8e19ae4ef9becd9fbc38fb4fd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 04:39:18 -1100 Subject: [PATCH 502/659] ,struct NSPV_CCmtxinfo *ptr --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 005a06380..5a650a8c9 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -614,7 +614,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 return(0); } -int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs) +int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; std::vector > unspentOutputs; From 9ea4e92c0cb23dab9023dff5069eb11941ac2606 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 04:39:42 -1100 Subject: [PATCH 503/659] Fix --- src/cc/CCtx.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 5a650a8c9..14cc5bc4a 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -619,9 +619,7 @@ int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinput int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; std::vector > unspentOutputs; if ( KOMODO_NSPV != 0 ) - { - //return(NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t num)); - } + return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr)); utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos)); if ( maxinputs > CC_MAXVINS ) maxinputs = CC_MAXVINS; From 99ba39fba136b268d0f98df8948015be2be11bcd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 04:42:44 -1100 Subject: [PATCH 504/659] Arg tweak --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 14cc5bc4a..cb9bf4a77 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -619,7 +619,7 @@ int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinput int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; std::vector > unspentOutputs; if ( KOMODO_NSPV != 0 ) - return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr)); + return(NSPV_AddNormalinputs(mtx,pubkey2pk(Mypubkey()),total,maxinputs,ptr)); utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos)); if ( maxinputs > CC_MAXVINS ) maxinputs = CC_MAXVINS; From 07d19ec210c14910dcc3f2c2d0975e019045c7df Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 05:33:05 -1100 Subject: [PATCH 505/659] Add nSPV to myGetTransaction --- src/cc/CCtx.cpp | 13 ++++++++----- src/main.cpp | 5 +++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index cb9bf4a77..2b02670ca 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -17,6 +17,7 @@ #include "key_io.h" std::vector NULL_pubkeys; +struct NSPV_CCmtxinfo NSPV_U; /* FinalizeCCTx is a very useful function that will properly sign both CC and normal inputs, adds normal change and the opreturn. @@ -96,8 +97,9 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran //This is a must to avoid hardfork change of validation in every CC, because there could be maximum one normal vin at the begining with current validation. for (i=0; i Date: Wed, 10 Jul 2019 05:35:57 -1100 Subject: [PATCH 506/659] Syntax --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 1f000aa4c..f81b04bbc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2223,7 +2223,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo if ( KOMODO_NSPV != 0 ) { int64_t rewardsum = 0; - return(NSPV_gettransaction(1,0,txid,0,txOut,0,0,rewardsum) == 0); + return(NSPV_gettransaction(1,0,hash,0,txOut,0,0,rewardsum) == 0); } // need a GetTransaction without lock so the validation code for assets can run without deadlock { From 86d6ba3d8737b63c63fa6d7cdfe9926d480fcf3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 06:21:04 -1100 Subject: [PATCH 507/659] Connect addressutxos to addnormalinputs --- src/cc/CCtx.cpp | 6 +++++- src/komodo_nSPV.h | 10 ++++++++++ src/komodo_nSPV_wallet.h | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 2b02670ca..977c1e37a 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -525,7 +525,11 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; if ( KOMODO_NSPV != 0 ) - return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr)); + { + if ( ptr != 0 ) + return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr)); + else return(0); + } #ifdef ENABLE_WALLET assert(pwalletMain != NULL); const CKeyStore& keystore = *pwalletMain; diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9c577512d..2c8086cae 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -128,6 +128,16 @@ void NSPV_utxosresp_purge(struct NSPV_utxosresp *ptr) } } +void NSPV_utxosresp_copy(struct NSPV_utxosresp *dest,struct NSPV_utxosresp *ptr) +{ + *dest = *ptr; + if ( ptr->utxos != 0 ) + { + dest->utxos = (struct NSPV_utxoresp *)malloc(ptr->numutxos * sizeof(*ptr->utxos)); + memcpy(dest->utxos,ptr->utxos,ptr->numutxos * sizeof(*ptr->utxos)); + } +} + int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) { int32_t len = 0; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index cb2e6ea79..08f2646d7 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -408,8 +408,16 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr) { + char coinaddr[64]; int32_t CCflag = 0; if ( ptr != 0 ) { + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); + if ( strcmp(ptr->U.coinaddr,coinaddr) != 0 ) + { + NSPV_addressutxos(coinaddr,CCflag); + NSPV_utxosresp_purge(&ptr->U); + NSPV_utxosresp_copy(&ptr->U,&NSPV_utxosresult); + } memset(ptr->used,0,sizeof(ptr->used)); return(NSPV_addinputs(ptr->used,mtx,total,maxinputs,ptr->U.utxos,ptr->U.numutxos)); } else return(0); From 4d3782db2483a20b5baa286755b802a0533171d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 06:26:26 -1100 Subject: [PATCH 508/659] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0821017ff..41fab362c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2387,7 +2387,7 @@ void komodo_args(char *argv0) if ( strcmp("ILN",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - CCDISABLEALL; + // CCDISABLEALL; } if ( strcmp("OUR",ASSETCHAINS_SYMBOL) == 0 ) { From 190b0d62d534b3910891ee2cd722675529a0b8ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 06:31:28 -1100 Subject: [PATCH 509/659] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ce59f7f67..fe038dc13 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7002,8 +7002,8 @@ UniValue faucetfund(const UniValue& params, bool fHelp) throw runtime_error("faucetfund amount\n"); if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + //const CKeyStore& keystore = *pwalletMain; + //LOCK2(cs_main, pwalletMain->cs_wallet); funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; if (funds > 0) { hex = FaucetFund(0,(uint64_t) funds); From 2af10c9963d998ebfb03bfbd669eee9afb467bb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 06:34:01 -1100 Subject: [PATCH 510/659] NSPV_U --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index cf12fae69..efac2bc75 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -226,7 +226,7 @@ std::string FaucetFund(uint64_t txfee,int64_t funds) txfee = 10000; mypk = pubkey2pk(Mypubkey()); faucetpk = GetUnspendable(cp,0); - if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) + if ( AddNormalinputs(mtx,mypk,funds+txfee,64,&NSPV_U) > 0 ) { mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,funds,faucetpk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); From 5a967b10d4b639b9a7614ea1e1aed263bc25e561 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 06:35:24 -1100 Subject: [PATCH 511/659] Extern --- src/cc/CCinclude.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 4fb5bfbe5..203a9c868 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -152,6 +152,7 @@ struct oracleprice_info }; typedef std::vector vscript_t; +extern struct NSPV_CCmtxinfo NSPV_U; #ifdef ENABLE_WALLET extern CWallet* pwalletMain; From 5c3b9e7142eb6693d673400ce96b651a7ecdf782 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 06:38:53 -1100 Subject: [PATCH 512/659] Use global --- src/cc/CCinclude.h | 4 ++-- src/cc/CCtx.cpp | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 203a9c868..53a2d050f 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -290,8 +290,8 @@ std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTr void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool CCflag = true); void SetCCtxids(std::vector > &addressIndex,char *coinaddr,bool CCflag = true); int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr); -int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr = 0); -int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr = 0); +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); +int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs); int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag); bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 977c1e37a..121271561 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -521,15 +521,11 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * else return(belowi); } -int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr) +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; if ( KOMODO_NSPV != 0 ) - { - if ( ptr != 0 ) - return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr)); - else return(0); - } + return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,&NSPV_U)); #ifdef ENABLE_WALLET assert(pwalletMain != NULL); const CKeyStore& keystore = *pwalletMain; @@ -621,12 +617,12 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 return(0); } -int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr) +int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; std::vector > unspentOutputs; if ( KOMODO_NSPV != 0 ) - return(NSPV_AddNormalinputs(mtx,pubkey2pk(Mypubkey()),total,maxinputs,ptr)); + return(NSPV_AddNormalinputs(mtx,pubkey2pk(Mypubkey()),total,maxinputs,&NPSV_U)); utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos)); if ( maxinputs > CC_MAXVINS ) maxinputs = CC_MAXVINS; From 2b0238c7d37960b26f69fb49471e54ecc822efad Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 06:45:06 -1100 Subject: [PATCH 513/659] Test --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 08f2646d7..6a664e454 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -228,7 +228,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C { CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; int64_t branchid = NSPV_BRANCHID; keystore.AddKey(NSPV_key); - if ( 0 ) + if ( 1 ) { int32_t i; for (i=0; i Date: Wed, 10 Jul 2019 07:11:55 -1100 Subject: [PATCH 514/659] NSPV --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 121271561..5e81c4b26 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -622,7 +622,7 @@ int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinput int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; std::vector > unspentOutputs; if ( KOMODO_NSPV != 0 ) - return(NSPV_AddNormalinputs(mtx,pubkey2pk(Mypubkey()),total,maxinputs,&NPSV_U)); + return(NSPV_AddNormalinputs(mtx,pubkey2pk(Mypubkey()),total,maxinputs,&NSPV_U)); utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos)); if ( maxinputs > CC_MAXVINS ) maxinputs = CC_MAXVINS; From 0c76dbf7ace84d42226052e7359174c45f44c9ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 07:31:07 -1100 Subject: [PATCH 515/659] -arg --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index efac2bc75..cf12fae69 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -226,7 +226,7 @@ std::string FaucetFund(uint64_t txfee,int64_t funds) txfee = 10000; mypk = pubkey2pk(Mypubkey()); faucetpk = GetUnspendable(cp,0); - if ( AddNormalinputs(mtx,mypk,funds+txfee,64,&NSPV_U) > 0 ) + if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) { mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,funds,faucetpk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); From d304ce41cfc5599720f834efc99b3d558fecced5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 07:46:10 -1100 Subject: [PATCH 516/659] -prints --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f81b04bbc..8f0225f27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2222,8 +2222,10 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo memset(&hashBlock,0,sizeof(hashBlock)); if ( KOMODO_NSPV != 0 ) { - int64_t rewardsum = 0; - return(NSPV_gettransaction(1,0,hash,0,txOut,0,0,rewardsum) == 0); + int64_t rewardsum = 0; int32_t retval,vout = 0; + retval = NSPV_gettransaction(1,vout,hash,0,txOut,0,0,rewardsum); + fprintf(stderr,"myGetTransaction retval.%d\n",retval); + return(retval == 0); } // need a GetTransaction without lock so the validation code for assets can run without deadlock { From a8863f6abdaa0667236ce2f1d070823080093289 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 07:50:43 -1100 Subject: [PATCH 517/659] Test --- src/komodo_nSPV_wallet.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 6a664e454..a5372358a 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -61,7 +61,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum) { struct NSPV_txproof *ptr; int32_t i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; - if ( (ptr= NSPV_txproof_find(txid)) == 0 ) + if ( (ptr= NSPV_txproof_find(txid)) == 0 && ptr->txprooflen != 0 ) { NSPV_txproof(vout,txid,height); ptr = &NSPV_txproofresult; @@ -82,6 +82,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); rewardsum += rewards; } + fprintf(stderr,"txid.%s vs hash.%s\n",txid.GetHex().c_str(),hash.GetHex().c_str()); if ( skipvalidation == 0 ) { From b5b5e24b39d3d5766bec89c7046eb12d6b03d9ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 07:51:53 -1100 Subject: [PATCH 518/659] Tx --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index a5372358a..3e766763a 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -82,7 +82,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); rewardsum += rewards; } - fprintf(stderr,"txid.%s vs hash.%s\n",txid.GetHex().c_str(),hash.GetHex().c_str()); + fprintf(stderr,"txid.%s vs hash.%s\n",txid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); if ( skipvalidation == 0 ) { From 729a9ec2495dfcace7f6ef566e2dbf5ac1ce0290 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 07:54:51 -1100 Subject: [PATCH 519/659] Fix --- src/komodo_nSPV_wallet.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 3e766763a..7b8627c9a 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -61,7 +61,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum) { struct NSPV_txproof *ptr; int32_t i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; - if ( (ptr= NSPV_txproof_find(txid)) == 0 && ptr->txprooflen != 0 ) + if ( (ptr= NSPV_txproof_find(txid)) == 0 || ptr->txprooflen != 0 ) { NSPV_txproof(vout,txid,height); ptr = &NSPV_txproofresult; @@ -73,8 +73,10 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int } else if ( NSPV_txextract(tx,ptr->tx,ptr->txlen) < 0 || ptr->txlen <= 0 ) retval = -2000; - else if ( skipvalidation == 0 && ptr->unspentvalue <= 0 ) + else if ( tx.GetHash() != txid ) retval = -2001; + else if ( skipvalidation == 0 && ptr->unspentvalue <= 0 ) + retval = -2002; else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) { rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); @@ -118,7 +120,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int retval = -2003; } } - } else retval = -2002; + } else retval = -2005; } else retval = -2004; } return(retval); From 725c260572c6e7d90c5b369d02620e6386f0a1f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 07:57:39 -1100 Subject: [PATCH 520/659] Print --- src/komodo_nSPV_wallet.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 7b8627c9a..9b494164c 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -84,7 +84,9 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); rewardsum += rewards; } - fprintf(stderr,"txid.%s vs hash.%s\n",txid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + char coinaddr[64]; + Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); + fprintf(stderr,"%s txid.%s vs hash.%s\n",coinaddr,txid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); if ( skipvalidation == 0 ) { From f7a0c7aee5201de3ba5869fe180682c4d954f64d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 08:03:17 -1100 Subject: [PATCH 521/659] +print --- src/cc/CCtx.cpp | 5 +++++ src/komodo_nSPV_wallet.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 5e81c4b26..e0270fd4f 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -158,6 +158,11 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { if ( KOMODO_NSPV == 0 ) { + { + char addr[64]; + Getscriptaddress(addr,vintx.vout[utxovout].scriptPubKey); + fprintf(stderr,"vout[%d] %.8f -> %s\n",utxovout,dstr(vintx.vout[utxovout].nValue),addr); + } if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask); } diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 9b494164c..e10e3be58 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -61,7 +61,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum) { struct NSPV_txproof *ptr; int32_t i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; - if ( (ptr= NSPV_txproof_find(txid)) == 0 || ptr->txprooflen != 0 ) + if ( (ptr= NSPV_txproof_find(txid)) == 0 ) { NSPV_txproof(vout,txid,height); ptr = &NSPV_txproofresult; @@ -86,7 +86,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int } char coinaddr[64]; Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); - fprintf(stderr,"%s txid.%s vs hash.%s\n",coinaddr,txid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + //fprintf(stderr,"%s txid.%s vs hash.%s\n",coinaddr,txid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); if ( skipvalidation == 0 ) { From ffcbd2407a26e7b4a6b821022fce43fa032d6690 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 08:05:57 -1100 Subject: [PATCH 522/659] Right place --- src/cc/CCtx.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index e0270fd4f..96b22adad 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -158,16 +158,16 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { if ( KOMODO_NSPV == 0 ) { - { - char addr[64]; - Getscriptaddress(addr,vintx.vout[utxovout].scriptPubKey); - fprintf(stderr,"vout[%d] %.8f -> %s\n",utxovout,dstr(vintx.vout[utxovout].nValue),addr); - } if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 ) fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask); } else { + { + char addr[64]; + Getscriptaddress(addr,vintx.vout[utxovout].scriptPubKey); + fprintf(stderr,"vout[%d] %.8f -> %s\n",utxovout,dstr(vintx.vout[utxovout].nValue),addr); + } if ( NSPV_SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey,0) == 0 ) fprintf(stderr,"NSPV signing error for vini.%d of %llx\n",i,(long long)vinimask); } From 83b7596ebf5871e692f9ff7c73e2658a8c8412f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 08:11:42 -1100 Subject: [PATCH 523/659] Test --- src/cc/CCtx.cpp | 2 ++ src/komodo_nSPV_wallet.h | 7 ------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 96b22adad..d1e1217b0 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -165,6 +165,8 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { { char addr[64]; + Getscriptaddress(addr,vintx.vout[0].scriptPubKey); + fprintf(stderr,"vout[%d] %.8f -> %s\n",0,dstr(vintx.vout[0].nValue),addr); Getscriptaddress(addr,vintx.vout[utxovout].scriptPubKey); fprintf(stderr,"vout[%d] %.8f -> %s\n",utxovout,dstr(vintx.vout[utxovout].nValue),addr); } diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index e10e3be58..d38f52722 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -233,13 +233,6 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C { CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; int64_t branchid = NSPV_BRANCHID; keystore.AddKey(NSPV_key); - if ( 1 ) - { - int32_t i; - for (i=0; i Date: Wed, 10 Jul 2019 21:11:49 -1100 Subject: [PATCH 524/659] Sapling for nSPV --- src/komodo_gateway.h | 3 ++- src/main.cpp | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5c60503bf..0093cd38a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -652,7 +652,8 @@ const char *banned_txids[] = //"01d8c839463bda2f2f6400ede4611357913684927a767422a8560ead1b22557c", //"6e4980a9e1bd669f4df04732dc6f11b7773b6de88d1abcf89a6b9007d72ef9ac", //"6cc1d0495170bc0e11fd3925297623562e529ea1336b66ea61f8a1159041aed2", - //"250875424cece9bcd98cb226b09da7671625633d6958589e3a462bad89ad87cc", // missed + //"250875424cece9bcd98cb226b09da7671625633d6958589e3a462bad89ad87cc", // missed + //"ea8659011de52f4dac42cda12326064b7b5013b8492f88e33159884ca299aa05", // missed }; int32_t komodo_checkvout(int32_t vout,int32_t k,int32_t indallvouts) diff --git a/src/main.cpp b/src/main.cpp index 8f0225f27..e7444bad3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8468,20 +8468,22 @@ CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Para { CMutableTransaction mtx; - bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); + bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER) || (KOMODO_NSPV != 0); if (isOverwintered) { mtx.fOverwintered = true; mtx.nExpiryHeight = nHeight + expiryDelta; - if (NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) { + if ( NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING) || (KOMODO_NSPV != 0) ) + { mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; - } else { + } + else + { mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID; mtx.nVersion = OVERWINTER_TX_VERSION; - mtx.nExpiryHeight = std::min( - mtx.nExpiryHeight, - static_cast(consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight - 1)); + mtx.nExpiryHeight = std::min(mtx.nExpiryHeight, + static_cast(consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight -1)); } } return mtx; From 3ec201770581e1a1daa8d69b8e7bd8f58dd84197 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 21:17:19 -1100 Subject: [PATCH 525/659] No expiry --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e7444bad3..57f21a80b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2224,7 +2224,6 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo { int64_t rewardsum = 0; int32_t retval,vout = 0; retval = NSPV_gettransaction(1,vout,hash,0,txOut,0,0,rewardsum); - fprintf(stderr,"myGetTransaction retval.%d\n",retval); return(retval == 0); } // need a GetTransaction without lock so the validation code for assets can run without deadlock @@ -8471,7 +8470,8 @@ CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Para bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER) || (KOMODO_NSPV != 0); if (isOverwintered) { mtx.fOverwintered = true; - mtx.nExpiryHeight = nHeight + expiryDelta; + if ( KOMODO_NSPV == 0 ) + mtx.nExpiryHeight = nHeight + expiryDelta; if ( NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING) || (KOMODO_NSPV != 0) ) { From e351db5325b54b9d84b405a650660ec0ee357e14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 21:25:27 -1100 Subject: [PATCH 526/659] Spend to scriptPubKey --- src/komodo_nSPV_wallet.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index d38f52722..ffb1c0311 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -299,7 +299,7 @@ std::string NSPV_signtx(int64_t &rewardsum,int64_t &interestsum,UniValue &retcod UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! { - UniValue result(UniValue::VOBJ),retcodes(UniValue::VARR); uint8_t rmd160[128]; int64_t txfee = 10000; + UniValue result(UniValue::VOBJ),retcodes(UniValue::VARR); CScript scriptPubKey; uint8_t rmd160[128]; int64_t txfee = 10000; if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) { result.push_back(Pair("result","error")); @@ -315,10 +315,16 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a } else if ( bitcoin_base58decode(rmd160,destaddr) != 25 ) { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","invalid destaddr")); - return(result); + if ( is_hexstr(destaddr) > 0 ) + scriptPubKey = CScript() << ParseHex(destaddr); + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid destaddr")); + return(result); + } } + else scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG); if ( NSPV_inforesult.height == 0 ) { result.push_back(Pair("result","error")); @@ -359,7 +365,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a if ( NSPV_addinputs(used,mtx,satoshis+txfee,64,NSPV_utxosresult.utxos,NSPV_utxosresult.numutxos) > 0 ) { - mtx.vout.push_back(CTxOut(satoshis,CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(satoshis,scriptPubKey); if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) { result.push_back(Pair("result","error")); From 312ad7dc2455ef6f2eca958ab868162253c9b0b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 21:28:20 -1100 Subject: [PATCH 527/659] Rearrange --- src/komodo_nSPV_wallet.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index ffb1c0311..8f11c3b44 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -299,7 +299,7 @@ std::string NSPV_signtx(int64_t &rewardsum,int64_t &interestsum,UniValue &retcod UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! { - UniValue result(UniValue::VOBJ),retcodes(UniValue::VARR); CScript scriptPubKey; uint8_t rmd160[128]; int64_t txfee = 10000; + UniValue result(UniValue::VOBJ),retcodes(UniValue::VARR); std::vector data; CScript scriptPubKey; uint8_t rmd160[128]; int64_t txfee = 10000; if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) { result.push_back(Pair("result","error")); @@ -315,7 +315,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a } else if ( bitcoin_base58decode(rmd160,destaddr) != 25 ) { - if ( is_hexstr(destaddr) > 0 ) + if ( is_hexstr(destaddr,0) > 0 ) scriptPubKey = CScript() << ParseHex(destaddr); else { @@ -324,7 +324,12 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } } - else scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG); + else + { + data.resize(20); + memcpy(&data[0],&rmd160[1],20); + scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG); + } if ( NSPV_inforesult.height == 0 ) { result.push_back(Pair("result","error")); @@ -352,7 +357,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); - std::vector data; CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction tx; int64_t rewardsum=0,interestsum=0; + CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction tx; int64_t rewardsum=0,interestsum=0; mtx.fOverwintered = true; mtx.nExpiryHeight = 0; mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; @@ -360,8 +365,6 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a if ( ASSETCHAINS_SYMBOL[0] == 0 ) mtx.nLockTime = (uint32_t)time(NULL) - 777; memset(used,0,sizeof(used)); - data.resize(20); - memcpy(&data[0],&rmd160[1],20); if ( NSPV_addinputs(used,mtx,satoshis+txfee,64,NSPV_utxosresult.utxos,NSPV_utxosresult.numutxos) > 0 ) { From 1983e7036888c23ce1e108d00c61517361a570fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 21:29:51 -1100 Subject: [PATCH 528/659] +( --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 8f11c3b44..e625a21d8 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -328,7 +328,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a { data.resize(20); memcpy(&data[0],&rmd160[1],20); - scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG); + scriptPubKey = (CScript() << OP_DUP << OP_HASH160 << ParseHex(HexStr(data)) << OP_EQUALVERIFY << OP_CHECKSIG); } if ( NSPV_inforesult.height == 0 ) { From cdac9257956a2bacdd335008e6fdfe510b0c7be5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 21:30:48 -1100 Subject: [PATCH 529/659] +) --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index e625a21d8..f2e645bd7 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -368,7 +368,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a if ( NSPV_addinputs(used,mtx,satoshis+txfee,64,NSPV_utxosresult.utxos,NSPV_utxosresult.numutxos) > 0 ) { - mtx.vout.push_back(CTxOut(satoshis,scriptPubKey); + mtx.vout.push_back(CTxOut(satoshis,scriptPubKey)); if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) { result.push_back(Pair("result","error")); From 40f2cf29c472301ec51c082f2eb0e7f44acb7996 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 21:42:51 -1100 Subject: [PATCH 530/659] Test --- src/komodo_nSPV_superlite.h | 1 + src/komodo_nSPV_wallet.h | 10 +++++----- src/main.cpp | 18 ++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 7c5039b78..d51d0a0ff 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -431,6 +431,7 @@ UniValue NSPV_broadcast_json(struct NSPV_broadcastresp *ptr,uint256 txid) UniValue NSPV_login(char *wifstr) { UniValue result(UniValue::VOBJ); char coinaddr[64]; uint8_t data[128]; int32_t len,valid = 0; + NSPV_logout(); len = bitcoin_base58decode(data,wifstr); if ( strlen(wifstr) < 64 && (len == 38 && data[len-5] == 1) || (len == 37 && data[len-5] != 1) ) valid = 1; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index f2e645bd7..509886697 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -238,10 +238,14 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C fprintf(stderr,"use legacy sig validation\n"); branchid = 0; } + mtx.fOverwintered = true; + mtx.nExpiryHeight = 0; + mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; + mtx.nVersion = branchid; if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,branchid) != 0 ) { UpdateTransaction(mtx,vini,sigdata); - // fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); } else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); @@ -358,10 +362,6 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a } printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction tx; int64_t rewardsum=0,interestsum=0; - mtx.fOverwintered = true; - mtx.nExpiryHeight = 0; - mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; - mtx.nVersion = SAPLING_TX_VERSION; if ( ASSETCHAINS_SYMBOL[0] == 0 ) mtx.nLockTime = (uint32_t)time(NULL) - 777; memset(used,0,sizeof(used)); diff --git a/src/main.cpp b/src/main.cpp index 57f21a80b..8f0225f27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2224,6 +2224,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo { int64_t rewardsum = 0; int32_t retval,vout = 0; retval = NSPV_gettransaction(1,vout,hash,0,txOut,0,0,rewardsum); + fprintf(stderr,"myGetTransaction retval.%d\n",retval); return(retval == 0); } // need a GetTransaction without lock so the validation code for assets can run without deadlock @@ -8467,23 +8468,20 @@ CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Para { CMutableTransaction mtx; - bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER) || (KOMODO_NSPV != 0); + bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); if (isOverwintered) { mtx.fOverwintered = true; - if ( KOMODO_NSPV == 0 ) - mtx.nExpiryHeight = nHeight + expiryDelta; + mtx.nExpiryHeight = nHeight + expiryDelta; - if ( NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING) || (KOMODO_NSPV != 0) ) - { + if (NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) { mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; - } - else - { + } else { mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID; mtx.nVersion = OVERWINTER_TX_VERSION; - mtx.nExpiryHeight = std::min(mtx.nExpiryHeight, - static_cast(consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight -1)); + mtx.nExpiryHeight = std::min( + mtx.nExpiryHeight, + static_cast(consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight - 1)); } } return mtx; From 97bea40b398f245221b67c9eb504ce590a078776 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 21:45:22 -1100 Subject: [PATCH 531/659] Revert --- src/komodo_nSPV_wallet.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 509886697..c2c65111f 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -238,10 +238,6 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C fprintf(stderr,"use legacy sig validation\n"); branchid = 0; } - mtx.fOverwintered = true; - mtx.nExpiryHeight = 0; - mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; - mtx.nVersion = branchid; if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,branchid) != 0 ) { UpdateTransaction(mtx,vini,sigdata); @@ -362,6 +358,10 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a } printf("%s numutxos.%d balance %.8f\n",NSPV_utxosresult.coinaddr,NSPV_utxosresult.numutxos,(double)NSPV_utxosresult.total/COIN); CScript opret; std::string hex; struct NSPV_utxoresp used[NSPV_MAXVINS]; CMutableTransaction mtx; CTransaction tx; int64_t rewardsum=0,interestsum=0; + mtx.fOverwintered = true; + mtx.nExpiryHeight = 0; + mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; + mtx.nVersion = SAPLING_TX_VERSION; if ( ASSETCHAINS_SYMBOL[0] == 0 ) mtx.nLockTime = (uint32_t)time(NULL) - 777; memset(used,0,sizeof(used)); From 3a50d1a9b9a81b1e1914bf3bd5aa60967fa5fc48 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 21:48:19 -1100 Subject: [PATCH 532/659] mtx init --- src/komodo_nSPV_wallet.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index c2c65111f..cfd450f14 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -418,6 +418,10 @@ int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total char coinaddr[64]; int32_t CCflag = 0; if ( ptr != 0 ) { + mtx.fOverwintered = true; + mtx.nExpiryHeight = 0; + mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; + mtx.nVersion = SAPLING_TX_VERSION; Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( strcmp(ptr->U.coinaddr,coinaddr) != 0 ) { From 1fd0425265d3136253d5a01d4c9a4288732525d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 21:56:28 -1100 Subject: [PATCH 533/659] Raw script --- src/komodo_nSPV_wallet.h | 11 ++++++++--- src/main.cpp | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index cfd450f14..fc7a293fd 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -299,7 +299,7 @@ std::string NSPV_signtx(int64_t &rewardsum,int64_t &interestsum,UniValue &retcod UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! { - UniValue result(UniValue::VOBJ),retcodes(UniValue::VARR); std::vector data; CScript scriptPubKey; uint8_t rmd160[128]; int64_t txfee = 10000; + UniValue result(UniValue::VOBJ),retcodes(UniValue::VARR); CScript scriptPubKey; uint8_t *data,rmd160[128]; int32_t len; int64_t txfee = 10000; if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) { result.push_back(Pair("result","error")); @@ -315,8 +315,13 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a } else if ( bitcoin_base58decode(rmd160,destaddr) != 25 ) { - if ( is_hexstr(destaddr,0) > 0 ) - scriptPubKey = CScript() << ParseHex(destaddr); + if ( (len= is_hexstr(destaddr,0)) > 0 ) + { + len >>= 1; + scriptPubKey.resize(len); + data = (uint8_t *)scriptPubKey.begin(); + decode_hex(data,len,destaddr); + } else { result.push_back(Pair("result","error")); diff --git a/src/main.cpp b/src/main.cpp index 8f0225f27..d2b16b2a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2224,7 +2224,6 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo { int64_t rewardsum = 0; int32_t retval,vout = 0; retval = NSPV_gettransaction(1,vout,hash,0,txOut,0,0,rewardsum); - fprintf(stderr,"myGetTransaction retval.%d\n",retval); return(retval == 0); } // need a GetTransaction without lock so the validation code for assets can run without deadlock From 97ca6a1a51388fbcab0b6630810ec7eba3d545ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:01:00 -1100 Subject: [PATCH 534/659] Test --- src/komodo_nSPV_wallet.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index fc7a293fd..3b1b88180 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -299,7 +299,7 @@ std::string NSPV_signtx(int64_t &rewardsum,int64_t &interestsum,UniValue &retcod UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! { - UniValue result(UniValue::VOBJ),retcodes(UniValue::VARR); CScript scriptPubKey; uint8_t *data,rmd160[128]; int32_t len; int64_t txfee = 10000; + UniValue result(UniValue::VOBJ),retcodes(UniValue::VARR); std::vector data; CScript scriptPubKey; uint8_t *ptr,rmd160[128]; int32_t len; int64_t txfee = 10000; if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) { result.push_back(Pair("result","error")); @@ -318,9 +318,9 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a if ( (len= is_hexstr(destaddr,0)) > 0 ) { len >>= 1; - scriptPubKey.resize(len); - data = (uint8_t *)scriptPubKey.begin(); - decode_hex(data,len,destaddr); + data.resize(len); + decode_hex(&data[0],len,destaddr); + scriptPubKey = CScript() << data << OP_CHECKCRYPTOCONDITION; } else { From ffd97afa0f5183e1f53b70a931b7f11f2ebd76fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:06:21 -1100 Subject: [PATCH 535/659] Test --- src/main.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d2b16b2a6..79822f93c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8466,21 +8466,31 @@ extern "C" const char* getDataDir() CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight) { CMutableTransaction mtx; - - bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); - if (isOverwintered) { + if ( KOMODO_NSPV != 0 ) + { mtx.fOverwintered = true; - mtx.nExpiryHeight = nHeight + expiryDelta; - - if (NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) { - mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; - mtx.nVersion = SAPLING_TX_VERSION; - } else { - mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID; - mtx.nVersion = OVERWINTER_TX_VERSION; - mtx.nExpiryHeight = std::min( - mtx.nExpiryHeight, - static_cast(consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight - 1)); + mtx.nExpiryHeight = 0; + mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; + mtx.nVersion = SAPLING_TX_VERSION; + } + else + { + bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); + if (isOverwintered) + { + mtx.fOverwintered = true; + mtx.nExpiryHeight = nHeight + expiryDelta; + if (NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) + { + mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; + mtx.nVersion = SAPLING_TX_VERSION; + } + else + { + mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID; + mtx.nVersion = OVERWINTER_TX_VERSION; + mtx.nExpiryHeight = std::min(mtx.nExpiryHeight,static_cast(consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight - 1)); + } } } return mtx; From 39993614d0bfea3943972648afd79815a9c91b36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:12:49 -1100 Subject: [PATCH 536/659] +prints --- src/script/sign.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index d0ae52b3a..784f2b8b8 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -51,8 +51,10 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) + { + fprintf(stderr,"keystore error\n"); return false; - + } if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; @@ -67,7 +69,10 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, if ( ASSETCHAINS_TXPOW == 0 ) { if (!key.Sign(hash, vchSig)) + { + fprintf(stderr,"key.Sign error\n"); return false; + } } else { From 14f86959b453c9aef27a0cb497edbd8101067717 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:19:06 -1100 Subject: [PATCH 537/659] Test --- src/komodo_nSPV_wallet.h | 4 ++-- src/script/sign.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 3b1b88180..2406ee5e3 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -241,9 +241,9 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,branchid) != 0 ) { UpdateTransaction(mtx,vini,sigdata); - fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + //fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); - } else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + } //else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); } diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 784f2b8b8..232953432 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -52,7 +52,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) { - fprintf(stderr,"keystore error\n"); + fprintf(stderr,"size.%d keystore.%p error\n",(int32_t)keystore.size(),keystore); return false; } if (scriptCode.IsPayToCryptoCondition()) From 3bab8916c2fd5438ae6b375f84f3656e8fb45a66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:23:22 -1100 Subject: [PATCH 538/659] Use global NSPV_key --- src/script/sign.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 232953432..e92634526 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -35,6 +35,8 @@ using namespace std; typedef vector valtype; extern uint8_t ASSETCHAINS_TXPOW; +extern CKey NSPV_key; +extern int32_t KOMODO_NSPV; uint256 SIG_TXHASH; TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} @@ -48,11 +50,13 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, return false; } SIG_TXHASH = hash; - if (pprivKey) + if ( KOMODO_NSPV != 0 ) + key = NSPV_key; + else if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) { - fprintf(stderr,"size.%d keystore.%p error\n",(int32_t)keystore.size(),keystore); + fprintf(stderr,"size.%d keystore.%p error\n",(int32_t)keystore->size(),keystore); return false; } if (scriptCode.IsPayToCryptoCondition()) From 2f62d0eec39e20a535f0be907a7ad4fe47b06f89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:24:25 -1100 Subject: [PATCH 539/659] -size --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index e92634526..aba91f953 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -56,7 +56,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) { - fprintf(stderr,"size.%d keystore.%p error\n",(int32_t)keystore->size(),keystore); + fprintf(stderr,"keystore.%p error\n",keystore); return false; } if (scriptCode.IsPayToCryptoCondition()) From 18a58c1c946ca7d8d908796952e4e54fc2b4e9aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:25:41 -1100 Subject: [PATCH 540/659] Declare --- src/komodo-tx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 67ac68cd4..04baecd39 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -47,6 +47,7 @@ using namespace std; #include "komodo_interest.h" +CKey NSPV_key; uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight) { return(0); From 32df8381f68d8a84394de16fc320d96340086755 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:35:28 -1100 Subject: [PATCH 541/659] +prints --- src/script/sign.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index aba91f953..df6d0422e 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -47,7 +47,10 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, try { hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, consensusBranchId); } catch (logic_error ex) { + { + fprintf(stderr,"logic error\n"); return false; + } } SIG_TXHASH = hash; if ( KOMODO_NSPV != 0 ) @@ -64,7 +67,10 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, CC *cc = (CC *)extraData; // assume either 1of1 or 1of2. if the condition created by the if (!cc || cc_signTreeSecp256k1Msg32(cc, key.begin(), hash.begin()) == 0) + { + fprintf(stderr,"CC tree error\n"); return false; + } vchSig = CCSigVec(cc); return true; } From a9997c32bc4638713f15148e418217f1e760e824 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:49:04 -1100 Subject: [PATCH 542/659] Test --- src/cc/CCtx.cpp | 2 -- src/komodo_nSPV_superlite.h | 22 +++++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index d1e1217b0..96b22adad 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -165,8 +165,6 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { { char addr[64]; - Getscriptaddress(addr,vintx.vout[0].scriptPubKey); - fprintf(stderr,"vout[%d] %.8f -> %s\n",0,dstr(vintx.vout[0].nValue),addr); Getscriptaddress(addr,vintx.vout[utxovout].scriptPubKey); fprintf(stderr,"vout[%d] %.8f -> %s\n",utxovout,dstr(vintx.vout[utxovout].nValue),addr); } diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d51d0a0ff..188d64c29 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -66,16 +66,32 @@ struct NSPV_ntzsresp *NSPV_ntzsresp_add(struct NSPV_ntzsresp *ptr) struct NSPV_txproof *NSPV_txproof_find(uint256 txid) { - int32_t i; + int32_t i; struct NSPV_txproof *backup = 0; for (i=0; itxprooflen != 0 ) + { + NSPV_txproof_purge(&NSPV_txproof_cache[i]); + NSPV_txproof_copy(&NSPV_txproof_cache[i],ptr); + return; + } + else if ( NSPV_txproof_cache[i].txprooflen != 0 || ptr->txprooflen == 0 ) + return; + } for (i=0; i Date: Wed, 10 Jul 2019 22:50:39 -1100 Subject: [PATCH 543/659] Fix --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 188d64c29..3215abab3 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -81,16 +81,16 @@ struct NSPV_txproof *NSPV_txproof_add(struct NSPV_txproof *ptr) { int32_t i; for (i=0; itxid ) { if ( NSPV_txproof_cache[i].txprooflen == 0 && ptr->txprooflen != 0 ) { NSPV_txproof_purge(&NSPV_txproof_cache[i]); NSPV_txproof_copy(&NSPV_txproof_cache[i],ptr); - return; + return(&NSPV_txproof_cache[i]); } else if ( NSPV_txproof_cache[i].txprooflen != 0 || ptr->txprooflen == 0 ) - return; + return(&NSPV_txproof_cache[i]); } for (i=0; i Date: Wed, 10 Jul 2019 22:53:58 -1100 Subject: [PATCH 544/659] +print --- src/script/sign.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index df6d0422e..8aaa4b191 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -83,6 +83,10 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, fprintf(stderr,"key.Sign error\n"); return false; } + else + { + fprintf(stderr,"signed success %s\n",HexStr(vchSig)); + } } else { From cf5d65336510993c795946888e2b6a1bb4f85758 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 22:54:50 -1100 Subject: [PATCH 545/659] Cast --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 8aaa4b191..2ea5bd78f 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -85,7 +85,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } else { - fprintf(stderr,"signed success %s\n",HexStr(vchSig)); + fprintf(stderr,"signed success %s\n",(char *)HexStr(vchSig).c_str()); } } else From a6c16efaa26780848f724eac575bfe2e94b3eded Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 23:53:09 -1100 Subject: [PATCH 546/659] +print --- src/script/sign.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 2ea5bd78f..6516c7176 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -104,7 +104,10 @@ static bool Sign1(const CKeyID& address, const BaseSignatureCreator& creator, co { vector vchSig; if (!creator.CreateSig(vchSig, address, scriptCode, consensusBranchId)) + { + fprintf(stderr,"Sign1 creatsig error\n"); return false; + } ret.push_back(vchSig); return true; } From f6f3fc8606daa33c70f7da575e399b89bfc558d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 00:06:06 -1100 Subject: [PATCH 547/659] Rpcwallet bypass --- src/cc/faucet.cpp | 1 + src/wallet/rpcwallet.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index cf12fae69..25eb5271d 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -221,6 +221,7 @@ std::string FaucetFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk,faucetpk; CScript opret; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fe038dc13..76924be44 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7000,11 +7000,19 @@ UniValue faucetfund(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); int64_t funds; std::string hex; if ( fHelp || params.size() > 1 ) throw runtime_error("faucetfund amount\n"); + funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; + if ( KOMODO_NSPV != 0 ) + { + char coinaddr[64]; struct CCcontract_info *cp,C; CTxOut v; + cp = CCinit(&C,EVAL_FAUCET); + v = MakeCC1vout(EVAL_FAUCET,funds,GetUnspendable(cp,0)); + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pubkey2pk(Mypubkey()))) << OP_CHECKSIG); + return(NSPV_spend(srcaddr,HexStr(v.scriptPubKey.begin(),v.scriptPubKey.end()),funds)); + } if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - //const CKeyStore& keystore = *pwalletMain; - //LOCK2(cs_main, pwalletMain->cs_wallet); - funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); if (funds > 0) { hex = FaucetFund(0,(uint64_t) funds); if ( hex.size() > 0 ) From c3f1008f80c3fa00ce1b366b3345c370e9abee34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 00:08:58 -1100 Subject: [PATCH 548/659] Syntax --- src/komodo_nSPV_defs.h | 1 + src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 537a7209e..c72fb2aeb 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -41,6 +41,7 @@ #define NSPV_BROADCASTRESP 0x0d int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum); +UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); extern uint256 SIG_TXHASH; uint32_t NSPV_blocktime(int32_t hdrheight); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 76924be44..e4a559bc4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7007,7 +7007,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) cp = CCinit(&C,EVAL_FAUCET); v = MakeCC1vout(EVAL_FAUCET,funds,GetUnspendable(cp,0)); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pubkey2pk(Mypubkey()))) << OP_CHECKSIG); - return(NSPV_spend(srcaddr,HexStr(v.scriptPubKey.begin(),v.scriptPubKey.end()),funds)); + return(NSPV_spend(coinaddr,HexStr(v.scriptPubKey.begin(),v.scriptPubKey.end()),funds)); } if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From e9707b1fde9448caac3512f79f4a87b9251f69ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 00:32:45 -1100 Subject: [PATCH 549/659] c_str --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e4a559bc4..3b7c45cde 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7007,7 +7007,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) cp = CCinit(&C,EVAL_FAUCET); v = MakeCC1vout(EVAL_FAUCET,funds,GetUnspendable(cp,0)); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pubkey2pk(Mypubkey()))) << OP_CHECKSIG); - return(NSPV_spend(coinaddr,HexStr(v.scriptPubKey.begin(),v.scriptPubKey.end()),funds)); + return(NSPV_spend(coinaddr,HexStr(v.scriptPubKey.begin(),v.scriptPubKey.end()).c_str(),funds)); } if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From 90e5dddda9a5513e86ccc802f67ca40d05184ce2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 00:33:55 -1100 Subject: [PATCH 550/659] Char * --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3b7c45cde..16378c592 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7007,7 +7007,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) cp = CCinit(&C,EVAL_FAUCET); v = MakeCC1vout(EVAL_FAUCET,funds,GetUnspendable(cp,0)); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pubkey2pk(Mypubkey()))) << OP_CHECKSIG); - return(NSPV_spend(coinaddr,HexStr(v.scriptPubKey.begin(),v.scriptPubKey.end()).c_str(),funds)); + return(NSPV_spend(coinaddr,(char *)HexStr(v.scriptPubKey.begin(),v.scriptPubKey.end()).c_str(),funds)); } if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From 635602d51982f81fb3809b01c949b6eadf1efa7c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 00:40:06 -1100 Subject: [PATCH 551/659] Off by 1 --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 16378c592..c11c4e7b2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7007,7 +7007,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) cp = CCinit(&C,EVAL_FAUCET); v = MakeCC1vout(EVAL_FAUCET,funds,GetUnspendable(cp,0)); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pubkey2pk(Mypubkey()))) << OP_CHECKSIG); - return(NSPV_spend(coinaddr,(char *)HexStr(v.scriptPubKey.begin(),v.scriptPubKey.end()).c_str(),funds)); + return(NSPV_spend(coinaddr,(char *)HexStr(v.scriptPubKey.begin()+1,v.scriptPubKey.end()-1).c_str(),funds)); } if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From 4dfad9f720e1092fd1e3701f64680e957503b81c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 00:42:45 -1100 Subject: [PATCH 552/659] Bypass --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c11c4e7b2..49c419c3d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7001,7 +7001,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("faucetfund amount\n"); funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; - if ( KOMODO_NSPV != 0 ) + if ( (0) && KOMODO_NSPV != 0 ) { char coinaddr[64]; struct CCcontract_info *cp,C; CTxOut v; cp = CCinit(&C,EVAL_FAUCET); From 6ee665057fb3a2dab0caa4ba2cdbb82fe809bcba Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 00:45:20 -1100 Subject: [PATCH 553/659] No lock --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 49c419c3d..968777b32 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7011,8 +7011,8 @@ UniValue faucetfund(const UniValue& params, bool fHelp) } if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + //const CKeyStore& keystore = *pwalletMain; + //LOCK2(cs_main, pwalletMain->cs_wallet); if (funds > 0) { hex = FaucetFund(0,(uint64_t) funds); if ( hex.size() > 0 ) From 3501a9cd4c1b5df9742cb7feed84e8991436eeb7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 00:54:11 -1100 Subject: [PATCH 554/659] Solved bypass --- src/script/sign.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 6516c7176..532c4d448 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -433,7 +433,8 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu } sigdata.scriptSig = PushAll(result); - + if ( KOMODO_NSPV != 0 ) + return(solved); // Test solution return solved && VerifyScript(sigdata.scriptSig, fromPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker(), consensusBranchId); } From 2a771477ce910a8195f22e2a7d92fe99a4bf806f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 01:33:53 -1100 Subject: [PATCH 555/659] Clear info N --- src/komodo_nSPV_fullnode.h | 1 + src/script/sign.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index bbc1712b8..da15c82e1 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -126,6 +126,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) { ptr->height = pindex->GetHeight(); ptr->blockhash = pindex->GetBlockHash(); + memset(&pair,0,sizeof(pair)); if ( NSPV_getntzsresp(&pair,ptr->height-1) < 0 ) return(-1); ptr->notarization = pair.prevntz; diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 532c4d448..3a9f658a2 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -85,7 +85,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } else { - fprintf(stderr,"signed success %s\n",(char *)HexStr(vchSig).c_str()); + //fprintf(stderr,"signed success %s\n",(char *)HexStr(vchSig).c_str()); } } else From b403b5a838c41aa65612c0f2a1559c0e0fd004a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 01:43:35 -1100 Subject: [PATCH 556/659] Enable --- src/script/sign.cpp | 2 -- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 3a9f658a2..31e4b49fc 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -433,8 +433,6 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu } sigdata.scriptSig = PushAll(result); - if ( KOMODO_NSPV != 0 ) - return(solved); // Test solution return solved && VerifyScript(sigdata.scriptSig, fromPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker(), consensusBranchId); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 968777b32..a597cc429 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7001,7 +7001,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("faucetfund amount\n"); funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; - if ( (0) && KOMODO_NSPV != 0 ) + if ( (1) && KOMODO_NSPV != 0 ) { char coinaddr[64]; struct CCcontract_info *cp,C; CTxOut v; cp = CCinit(&C,EVAL_FAUCET); From ca67f285cb2e9358c7cb65389e3ac27628c5da72 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 04:38:32 -1100 Subject: [PATCH 557/659] Fix rewards/validated --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 2406ee5e3..9fcbc760b 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -383,8 +383,8 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a hex = NSPV_signtx(rewardsum,interestsum,retcodes,mtx,txfee,opret,used); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - result.push_back(Pair("rewards",AmountFromValue(interestsum))); - result.push_back(Pair("validated",AmountFromValue(rewardsum))); + result.push_back(Pair("rewards",(double)interestsum/COIN)); + result.push_back(Pair("validated",(double)rewardsum/COIN)); } if ( hex.size() > 0 ) { From a3fefe3aeb1ee39bba2841dd41afd7fb7a712292 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 04:42:47 -1100 Subject: [PATCH 558/659] +print --- src/script/sign.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 31e4b49fc..e4ab3525d 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -359,7 +359,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP } CKeyID keyID; - + fprintf(stderr,"whichtype.%d vs %d\n",whichTypeRet,TX_PUBKEYHASH); switch (whichTypeRet) { case TX_NONSTANDARD: @@ -371,12 +371,16 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP case TX_PUBKEYHASH: keyID = CKeyID(uint160(vSolutions[0])); if (!Sign1(keyID, creator, scriptPubKey, ret, consensusBranchId)) + { + fprintf(stderr,"sign1 error\n"); return false; + } else { CPubKey vch; creator.KeyStore().GetPubKey(keyID, vch); ret.push_back(ToByteVector(vch)); + fprintf(stderr,"push pubkey\n"); } return true; case TX_SCRIPTHASH: From 382d683b1a8268c5d9ec490675b9725987d2697a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 04:54:25 -1100 Subject: [PATCH 559/659] %.8f --- src/komodo_nSPV_wallet.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 9fcbc760b..61d7487c8 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -383,8 +383,11 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a hex = NSPV_signtx(rewardsum,interestsum,retcodes,mtx,txfee,opret,used); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - result.push_back(Pair("rewards",(double)interestsum/COIN)); - result.push_back(Pair("validated",(double)rewardsum/COIN)); + char numstr[64]; + sprintf(numstr,"%.8f",(double)interestsum/COIN) + result.push_back(Pair("rewards",numstr)); + sprintf(numstr,"%.8f",(double)rewardsum/COIN) + result.push_back(Pair("validated",numstr)); } if ( hex.size() > 0 ) { From a85a56543d0dd078886197dc2a491255e58e5e0c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 04:56:48 -1100 Subject: [PATCH 560/659] ; --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 61d7487c8..3dc4b23f0 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -384,9 +384,9 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a if ( ASSETCHAINS_SYMBOL[0] == 0 ) { char numstr[64]; - sprintf(numstr,"%.8f",(double)interestsum/COIN) + sprintf(numstr,"%.8f",(double)interestsum/COIN); result.push_back(Pair("rewards",numstr)); - sprintf(numstr,"%.8f",(double)rewardsum/COIN) + sprintf(numstr,"%.8f",(double)rewardsum/COIN); result.push_back(Pair("validated",numstr)); } if ( hex.size() > 0 ) From 3cdc290bea7dfbd9e40757463fdef5cb25d85d07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 04:58:02 -1100 Subject: [PATCH 561/659] Fix display of interest/validated --- src/komodo_nSPV_wallet.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 300d5de22..569d0421f 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -371,8 +371,11 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a hex = NSPV_signtx(rewardsum,interestsum,retcodes,mtx,txfee,opret,used); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - result.push_back(Pair("rewards",AmountFromValue(interestsum))); - result.push_back(Pair("validated",AmountFromValue(rewardsum))); + char numstr[64]; + sprintf(numstr,"%.8f",(double)interestsum/COIN); + result.push_back(Pair("rewards",numstr)); + sprintf(numstr,"%.8f",(double)rewardsum/COIN); + result.push_back(Pair("validated",numstr)); } if ( hex.size() > 0 ) { From e25d27e8c2f8bd9af81e92a047db739938c161a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:00:55 -1100 Subject: [PATCH 562/659] Disable bypass --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a597cc429..968777b32 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7001,7 +7001,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("faucetfund amount\n"); funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; - if ( (1) && KOMODO_NSPV != 0 ) + if ( (0) && KOMODO_NSPV != 0 ) { char coinaddr[64]; struct CCcontract_info *cp,C; CTxOut v; cp = CCinit(&C,EVAL_FAUCET); From 200c155da6217485f2fc274d3b86eec2bbd96076 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:02:42 -1100 Subject: [PATCH 563/659] Print --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index e4ab3525d..1c33fd81a 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -380,7 +380,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP CPubKey vch; creator.KeyStore().GetPubKey(keyID, vch); ret.push_back(ToByteVector(vch)); - fprintf(stderr,"push pubkey\n"); + fprintf(stderr,"push pubkey %s\n",HexStr(vch).c_str()); } return true; case TX_SCRIPTHASH: From ca216319447b5dc468193545894d915d367f762c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:07:12 -1100 Subject: [PATCH 564/659] Test --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 1c33fd81a..ee188db63 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -380,7 +380,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP CPubKey vch; creator.KeyStore().GetPubKey(keyID, vch); ret.push_back(ToByteVector(vch)); - fprintf(stderr,"push pubkey %s\n",HexStr(vch).c_str()); + fprintf(stderr,"push pubkey %s %d\n",HexStr(vch).c_str(),TX_PUBKEYHASH); } return true; case TX_SCRIPTHASH: From 66247192444e9c52378bdd794efe7fae8d6580a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:10:13 -1100 Subject: [PATCH 565/659] Test --- src/script/sign.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index ee188db63..b775b03b0 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -377,10 +377,18 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP } else { - CPubKey vch; - creator.KeyStore().GetPubKey(keyID, vch); - ret.push_back(ToByteVector(vch)); - fprintf(stderr,"push pubkey %s %d\n",HexStr(vch).c_str(),TX_PUBKEYHASH); + if ( KOMODO_NSPV != 0 ) + { + extern char NSPV_pubkeystr[]; + fprintf(stderr,"push pubkey %s\n",NSPV_pubkeystr); + ret.push_back(ParseHex(NSPV_pubkeystr)); + } + else + { + CPubKey vch; + creator.KeyStore().GetPubKey(keyID, vch); + ret.push_back(ToByteVector(vch)); + } } return true; case TX_SCRIPTHASH: From 4e0ac4d995c2a8725eac9e9c7615a12236981100 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:11:34 -1100 Subject: [PATCH 566/659] extern char NSPV_pubkeystr[]; --- src/script/sign.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index b775b03b0..2e5354a0a 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -330,6 +330,8 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip * unless whichTypeRet is TX_SCRIPTHASH, in which case scriptSigRet is the redemption script. * Returns false if scriptPubKey could not be completely satisfied. */ +extern char NSPV_pubkeystr[]; + static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptPubKey, std::vector& ret, txnouttype& whichTypeRet, uint32_t consensusBranchId) { @@ -379,7 +381,6 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP { if ( KOMODO_NSPV != 0 ) { - extern char NSPV_pubkeystr[]; fprintf(stderr,"push pubkey %s\n",NSPV_pubkeystr); ret.push_back(ParseHex(NSPV_pubkeystr)); } From 72efa0be35c74ce335b14f87dd5f2057e9073c59 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:13:19 -1100 Subject: [PATCH 567/659] In komodo-tx --- src/komodo-tx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 04baecd39..2408dc076 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -48,6 +48,7 @@ using namespace std; #include "komodo_interest.h" CKey NSPV_key; +char NSPV_pubkeystr[67]; uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight) { return(0); From b41983c09c8dde782b88f4386c6f4f0a2ec05cf9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:15:13 -1100 Subject: [PATCH 568/659] Bypass verify --- src/script/sign.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 2e5354a0a..4face3f63 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -447,6 +447,8 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu sigdata.scriptSig = PushAll(result); // Test solution + if ( KOMODO_NSPV != 0 ) + return(solved); return solved && VerifyScript(sigdata.scriptSig, fromPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker(), consensusBranchId); } From 4b82f0d4f7957dc5ee59459fc759aade39402a52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:23:50 -1100 Subject: [PATCH 569/659] +print --- src/script/sign.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 4face3f63..c9182940d 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -62,6 +62,8 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, fprintf(stderr,"keystore.%p error\n",keystore); return false; } + fprintf(stderr,"privkey for %s\n",EncodeDestination(NSPV_key.GetPubKey().GetID()).c_str()); + if (scriptCode.IsPayToCryptoCondition()) { CC *cc = (CC *)extraData; @@ -330,8 +332,6 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip * unless whichTypeRet is TX_SCRIPTHASH, in which case scriptSigRet is the redemption script. * Returns false if scriptPubKey could not be completely satisfied. */ -extern char NSPV_pubkeystr[]; - static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptPubKey, std::vector& ret, txnouttype& whichTypeRet, uint32_t consensusBranchId) { @@ -379,17 +379,10 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP } else { - if ( KOMODO_NSPV != 0 ) - { - fprintf(stderr,"push pubkey %s\n",NSPV_pubkeystr); - ret.push_back(ParseHex(NSPV_pubkeystr)); - } - else - { - CPubKey vch; - creator.KeyStore().GetPubKey(keyID, vch); - ret.push_back(ToByteVector(vch)); - } + CPubKey vch; + creator.KeyStore().GetPubKey(keyID, vch); + ret.push_back(ToByteVector(vch)); + fprintf(stderr,"push pubkey (%s)\n",HexStr(vch).c_str()); } return true; case TX_SCRIPTHASH: @@ -447,8 +440,6 @@ bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPu sigdata.scriptSig = PushAll(result); // Test solution - if ( KOMODO_NSPV != 0 ) - return(solved); return solved && VerifyScript(sigdata.scriptSig, fromPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker(), consensusBranchId); } From 9deab4a00bbd591a5c603978867b6a616b82e102 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:26:43 -1100 Subject: [PATCH 570/659] Test --- src/script/sign.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index c9182940d..7a9bb4052 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -36,6 +36,7 @@ using namespace std; typedef vector valtype; extern uint8_t ASSETCHAINS_TXPOW; extern CKey NSPV_key; +extern char NSPV_wifstr[]; extern int32_t KOMODO_NSPV; uint256 SIG_TXHASH; @@ -62,7 +63,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, fprintf(stderr,"keystore.%p error\n",keystore); return false; } - fprintf(stderr,"privkey for %s\n",EncodeDestination(NSPV_key.GetPubKey().GetID()).c_str()); + fprintf(stderr,"privkey (%s) for %s\n",NSPV_wifstr,EncodeDestination(NSPV_key.GetPubKey().GetID()).c_str()); if (scriptCode.IsPayToCryptoCondition()) { From 13185e15df32f7c4dd4ec14a42a1e14c4df6b409 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:29:57 -1100 Subject: [PATCH 571/659] Test --- src/komodo-tx.cpp | 2 +- src/script/sign.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 2408dc076..084d99c80 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -48,7 +48,7 @@ using namespace std; #include "komodo_interest.h" CKey NSPV_key; -char NSPV_pubkeystr[67]; +char NSPV_pubkeystr[67],NSPV_wifstr[64]; uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight) { return(0); diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 7a9bb4052..5ede7987b 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -35,7 +35,6 @@ using namespace std; typedef vector valtype; extern uint8_t ASSETCHAINS_TXPOW; -extern CKey NSPV_key; extern char NSPV_wifstr[]; extern int32_t KOMODO_NSPV; uint256 SIG_TXHASH; @@ -55,7 +54,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } SIG_TXHASH = hash; if ( KOMODO_NSPV != 0 ) - key = NSPV_key; + key = DecodeSecret(wifstr); else if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) @@ -63,7 +62,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, fprintf(stderr,"keystore.%p error\n",keystore); return false; } - fprintf(stderr,"privkey (%s) for %s\n",NSPV_wifstr,EncodeDestination(NSPV_key.GetPubKey().GetID()).c_str()); + fprintf(stderr,"privkey (%s) for %s\n",NSPV_wifstr,EncodeDestination(key.GetPubKey().GetID()).c_str()); if (scriptCode.IsPayToCryptoCondition()) { From da62c118e2c455f5c1209af546d39f604c92aa21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:30:54 -1100 Subject: [PATCH 572/659] Extern --- src/script/sign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 5ede7987b..49e0d9ce2 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -54,7 +54,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } SIG_TXHASH = hash; if ( KOMODO_NSPV != 0 ) - key = DecodeSecret(wifstr); + key = DecodeSecret(NSPV_wifstr); else if (pprivKey) key = *pprivKey; else if (!keystore || !keystore->GetKey(address, key)) From 1b718659f6c4b0595db9ffa4cb6b8fb19e72d530 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:33:57 -1100 Subject: [PATCH 573/659] Test --- src/script/sign.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 49e0d9ce2..8a77217f1 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -62,7 +62,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, fprintf(stderr,"keystore.%p error\n",keystore); return false; } - fprintf(stderr,"privkey (%s) for %s\n",NSPV_wifstr,EncodeDestination(key.GetPubKey().GetID()).c_str()); + //fprintf(stderr,"privkey (%s) for %s\n",NSPV_wifstr,EncodeDestination(key.GetPubKey().GetID()).c_str()); if (scriptCode.IsPayToCryptoCondition()) { @@ -361,7 +361,6 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP } CKeyID keyID; - fprintf(stderr,"whichtype.%d vs %d\n",whichTypeRet,TX_PUBKEYHASH); switch (whichTypeRet) { case TX_NONSTANDARD: @@ -379,10 +378,17 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP } else { - CPubKey vch; - creator.KeyStore().GetPubKey(keyID, vch); - ret.push_back(ToByteVector(vch)); - fprintf(stderr,"push pubkey (%s)\n",HexStr(vch).c_str()); + if ( KOMODO_NSPV == 0 ) + { + CPubKey vch; + creator.KeyStore().GetPubKey(keyID, vch); + ret.push_back(ToByteVector(vch)); + } + else + { + ret.push_back(ParseHex(NSPV_pubkey)); + fprintf(stderr,"push pubkey (%s)\n",NSPV_pubkey); + } } return true; case TX_SCRIPTHASH: From 6a0f51d066edc4e531204355bfa80e146d9534b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:35:20 -1100 Subject: [PATCH 574/659] NSPV_pubkeystr --- src/script/sign.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 8a77217f1..5088f5ec0 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -35,7 +35,7 @@ using namespace std; typedef vector valtype; extern uint8_t ASSETCHAINS_TXPOW; -extern char NSPV_wifstr[]; +extern char NSPV_wifstr[],NSPV_pubkeystr[]; extern int32_t KOMODO_NSPV; uint256 SIG_TXHASH; @@ -386,8 +386,8 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP } else { - ret.push_back(ParseHex(NSPV_pubkey)); - fprintf(stderr,"push pubkey (%s)\n",NSPV_pubkey); + ret.push_back(ParseHex(NSPV_pubkeystr)); + fprintf(stderr,"push pubkey (%s)\n",NSPV_pubkeystr); } } return true; From dc7e92dd37de68e2ceaf6b86068f977a9fa16c39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:37:40 -1100 Subject: [PATCH 575/659] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 968777b32..a597cc429 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7001,7 +7001,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("faucetfund amount\n"); funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; - if ( (0) && KOMODO_NSPV != 0 ) + if ( (1) && KOMODO_NSPV != 0 ) { char coinaddr[64]; struct CCcontract_info *cp,C; CTxOut v; cp = CCinit(&C,EVAL_FAUCET); From 99313e742faa0bd38a9809c5fbfa9c1d06ec3bf6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 05:44:53 -1100 Subject: [PATCH 576/659] Tmp tmp wallet --- src/init.cpp | 1 + src/script/sign.cpp | 7 +------ src/wallet/rpcwallet.cpp | 6 +++--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 4adde6681..9296d17ac 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1496,6 +1496,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) InitBlockIndex(); SetRPCWarmupFinished(); uiInterface.InitMessage(_("Done loading")); + pwalletMain = new CWallet("tmptmp.wallet"); return !fRequestShutdown; } // ********************************************************* Step 7: load block chain diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 5088f5ec0..451a63d4b 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -383,12 +383,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP CPubKey vch; creator.KeyStore().GetPubKey(keyID, vch); ret.push_back(ToByteVector(vch)); - } - else - { - ret.push_back(ParseHex(NSPV_pubkeystr)); - fprintf(stderr,"push pubkey (%s)\n",NSPV_pubkeystr); - } + } else ret.push_back(ParseHex(NSPV_pubkeystr)); } return true; case TX_SCRIPTHASH: diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a597cc429..49c419c3d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7001,7 +7001,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("faucetfund amount\n"); funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; - if ( (1) && KOMODO_NSPV != 0 ) + if ( (0) && KOMODO_NSPV != 0 ) { char coinaddr[64]; struct CCcontract_info *cp,C; CTxOut v; cp = CCinit(&C,EVAL_FAUCET); @@ -7011,8 +7011,8 @@ UniValue faucetfund(const UniValue& params, bool fHelp) } if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - //const CKeyStore& keystore = *pwalletMain; - //LOCK2(cs_main, pwalletMain->cs_wallet); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); if (funds > 0) { hex = FaucetFund(0,(uint64_t) funds); if ( hex.size() > 0 ) From 04710fdf01dedacce9a0cf293454e8b558b705f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 13:55:33 -1100 Subject: [PATCH 577/659] -const in CBlockIndexWorkComparator https://github.com/jl777/komodo/issues/1606 --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e01cba61f..a8f333aa8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -147,7 +147,7 @@ namespace { struct CBlockIndexWorkComparator { - bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const { + bool operator()(CBlockIndex *pa, const CBlockIndex *pb) const { // First sort by most total work, ... if (ASSETCHAINS_LWMAPOS) { From 3f3f80723c4618f8c50321e7005f0ef81b0827a8 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Sat, 6 Jul 2019 19:16:53 +0200 Subject: [PATCH 578/659] jokers payments fix --- src/cc/payments.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index b6e85480c..be4d63271 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -314,6 +314,8 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & fIsMerge = true; else if ( DecodePaymentsReleaseOpRet(ccopret,createtxid,amountReleased) != 'R' ) return(eval->Invalid("could not decode ccopret")); + if ( tx.vout.back().scriptPubKey.IsOpReturn() ) + fHasOpret = true; mpz_set_si(mpzCheckamount,amountReleased); } else return(eval->Invalid("could not decode ccopret")); From bb6d8b7b99697bc4240f05cc7a575b396fb5e957 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Tue, 9 Jul 2019 22:17:00 +0200 Subject: [PATCH 579/659] fix ac_cbmaturity magic without other params --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1bf8dfbeb..e06b42b69 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2040,7 +2040,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); StartShutdown(); } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; From 51c44114466602f6cea7f2733d5f354fbdb0fdaf Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 5 Jul 2019 23:02:18 +0200 Subject: [PATCH 580/659] add ac_cbmaturity --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index d8e292431..9ffa147ea 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -46,7 +46,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; uint256 KOMODO_EARLYTXID; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,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,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,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,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e06b42b69..76ca5c7ae 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1839,6 +1839,7 @@ void komodo_args(char *argv0) Split(GetArg("-ac_decay",""), ASSETCHAINS_DECAY, 0); Split(GetArg("-ac_notarypay",""), ASSETCHAINS_NOTARY_PAY, 0); + for ( int i = 0; i < ASSETCHAINS_MAX_ERAS; i++ ) { if ( ASSETCHAINS_DECAY[i] == 100000000 && ASSETCHAINS_ENDSUBSIDY == 0 ) @@ -1872,6 +1873,7 @@ void komodo_args(char *argv0) ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0); + ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",100); //fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET); if ( ASSETCHAINS_CBOPRET != 0 ) { @@ -2184,6 +2186,10 @@ void komodo_args(char *argv0) { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_EARLYTXIDCONTRACT),(void *)&ASSETCHAINS_EARLYTXIDCONTRACT); } + if ( ASSETCHAINS_CBMATURITY != 100 ) + { + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_CBMATURITY),(void *)&ASSETCHAINS_CBMATURITY); + } } addn = GetArg("-seednode",""); @@ -2234,8 +2240,15 @@ void komodo_args(char *argv0) } if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; - else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); - if (ASSETCHAINS_LASTERA == 0 || is_STAKED(ASSETCHAINS_SYMBOL) != 0) + else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1);\ + if (ASSETCHAINS_CBMATURITY < 1) + { + fprintf(stderr,"ac_cbmaturity must be >0\n"); + StartShutdown(); + } + if (ASSETCHAINS_CBMATURITY != 100) + COINBASE_MATURITY = ASSETCHAINS_CBMATURITY; + else if (ASSETCHAINS_LASTERA == 0 || is_STAKED(ASSETCHAINS_SYMBOL) != 0) COINBASE_MATURITY = 1; //fprintf(stderr,"ASSETCHAINS_RPCPORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_RPCPORT); } From c7ecffc934af7715c6d6b2c367e84c904e418efe Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 5 Jul 2019 23:13:15 +0200 Subject: [PATCH 581/659] syntax, remove misplaced \ --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 76ca5c7ae..f72d11762 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2240,7 +2240,7 @@ void komodo_args(char *argv0) } if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; - else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1);\ + else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); if (ASSETCHAINS_CBMATURITY < 1) { fprintf(stderr,"ac_cbmaturity must be >0\n"); From a273e8fdedc78c50a4d310eb18fa8c5fdd8fa89e Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 5 Jul 2019 23:14:37 +0200 Subject: [PATCH 582/659] remove extra whitespace --- src/komodo_utils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f72d11762..08c28a2fd 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1839,7 +1839,6 @@ void komodo_args(char *argv0) Split(GetArg("-ac_decay",""), ASSETCHAINS_DECAY, 0); Split(GetArg("-ac_notarypay",""), ASSETCHAINS_NOTARY_PAY, 0); - for ( int i = 0; i < ASSETCHAINS_MAX_ERAS; i++ ) { if ( ASSETCHAINS_DECAY[i] == 100000000 && ASSETCHAINS_ENDSUBSIDY == 0 ) From 5b7afedaecf1799ba3620740c37e803cafea49a3 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 5 Jul 2019 23:39:32 +0200 Subject: [PATCH 583/659] fix ac_cbmaturity=100 case --- src/komodo_utils.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 08c28a2fd..57d652309 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1872,7 +1872,7 @@ void komodo_args(char *argv0) ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0); - ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",100); + ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",0); //fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET); if ( ASSETCHAINS_CBOPRET != 0 ) { @@ -2185,7 +2185,7 @@ void komodo_args(char *argv0) { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_EARLYTXIDCONTRACT),(void *)&ASSETCHAINS_EARLYTXIDCONTRACT); } - if ( ASSETCHAINS_CBMATURITY != 100 ) + if ( ASSETCHAINS_CBMATURITY != 0 ) { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_CBMATURITY),(void *)&ASSETCHAINS_CBMATURITY); } @@ -2240,15 +2240,16 @@ void komodo_args(char *argv0) if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); - if (ASSETCHAINS_CBMATURITY < 1) - { - fprintf(stderr,"ac_cbmaturity must be >0\n"); - StartShutdown(); - } - if (ASSETCHAINS_CBMATURITY != 100) + + if (ASSETCHAINS_CBMATURITY != 0) COINBASE_MATURITY = ASSETCHAINS_CBMATURITY; else if (ASSETCHAINS_LASTERA == 0 || is_STAKED(ASSETCHAINS_SYMBOL) != 0) COINBASE_MATURITY = 1; + if (COINBASE_MATURITY < 1) + { + fprintf(stderr,"ac_cbmaturity must be >0, shutting down\n"); + StartShutdown(); + } //fprintf(stderr,"ASSETCHAINS_RPCPORT (%s) %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_RPCPORT); } if ( ASSETCHAINS_RPCPORT == 0 ) From c267dcb2823ffe02ec261bfc6f5c03d9aabdc965 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 14:52:43 -1100 Subject: [PATCH 584/659] KOMODO_EARLYTXID_HEIGHT --- src/bitcoind.cpp | 2 +- src/cc/faucet.cpp | 2 +- src/cc/hempcoin_notes.txt | 4 ++-- src/komodo_bitcoind.h | 10 +++++----- src/komodo_defs.h | 2 +- src/komodo_utils.h | 2 +- src/miner.cpp | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index a356e20a7..0baadf620 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -72,7 +72,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) // Tell the main threads to shutdown. if (komodo_currentheight()>KOMODO_EARLYTXID_HEIGHT && KOMODO_EARLYTXID!=zeroid && ((height=tx_height(KOMODO_EARLYTXID))==0 || height>KOMODO_EARLYTXID_HEIGHT)) { - fprintf(stderr,"error: earlytx must be before block height 100 or tx does not exist\n"); + fprintf(stderr,"error: earlytx must be before block height %d or tx does not exist\n",KOMODO_EARLYTXID_HEIGHT); StartShutdown(); } if ( ASSETCHAINS_CBOPRET != 0 ) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 25eb5271d..fd3a8f60f 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -159,7 +159,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub continue; //char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( (nValue= IsFaucetvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { diff --git a/src/cc/hempcoin_notes.txt b/src/cc/hempcoin_notes.txt index 2fd72c897..04bf0e9ac 100644 --- a/src/cc/hempcoin_notes.txt +++ b/src/cc/hempcoin_notes.txt @@ -1,6 +1,6 @@ How this works: - - earlytxid must be a transaction included in the chain before block 100. The chain MUST not have any other of these type of tx before block 100, or someone may be able to change it and mess things up. - - When it gets to block 100, it takes the txid specified by the -earlytxid param (does not affect magic) + - earlytxid must be a transaction included in the chain before block KOMODO_EARLYTXID_HEIGHT. The chain MUST not have any other of these type of tx before block KOMODO_EARLYTXID_HEIGHT, or someone may be able to change it and mess things up. + - When it gets to block KOMODO_EARLYTXID_HEIGHT, it takes the txid specified by the -earlytxid param (does not affect magic) - Looks up the transaction searches for the opreturn, then permenantly appends it to the end of ac_script in RAM. - After every daemon restart, the first time the daemon mines a block, or receives a block that pays ac_script it will look up the op_return and save it again. - this enables it to always reach consensus but doesnt need to constantly keep looking up the tx in the chain. diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b3f870170..477c99ff2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2072,7 +2072,7 @@ bool komodo_appendACscriptpub() { CTransaction tx; uint256 blockhash; // get transaction and check that it occured before height 100. - if ( myGetTransaction(KOMODO_EARLYTXID,tx,blockhash) && mapBlockIndex[blockhash]->GetHeight() < 100 ) + if ( myGetTransaction(KOMODO_EARLYTXID,tx,blockhash) && mapBlockIndex[blockhash]->GetHeight() < KOMODO_EARLYTXID_HEIGHT ) { for (int i = 0; i < tx.vout.size(); i++) { @@ -2107,15 +2107,15 @@ void GetKomodoEarlytxidScriptPub() StartShutdown(); return; } - if ( chainActive.Height() < 100 ) + if ( chainActive.Height() < KOMODO_EARLYTXID_HEIGHT ) { - fprintf(stderr, "Cannot fetch -earlytxid before block 100.\n"); + fprintf(stderr, "Cannot fetch -earlytxid before block %d.\n",KOMODO_EARLYTXID_HEIGHT); StartShutdown(); return; } CTransaction tx; uint256 blockhash; int32_t i; // get transaction and check that it occured before height 100. - if ( myGetTransaction(KOMODO_EARLYTXID,tx,blockhash) && mapBlockIndex[blockhash]->GetHeight() < 100 ) + if ( myGetTransaction(KOMODO_EARLYTXID,tx,blockhash) && mapBlockIndex[blockhash]->GetHeight() < KOMODO_EARLYTXID_HEIGHT ) { for (i = 0; i < tx.vout.size(); i++) if ( tx.vout[i].scriptPubKey[0] == OP_RETURN ) @@ -2156,7 +2156,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { static bool didinit = false; - if ( !didinit && height > 100 && KOMODO_EARLYTXID != zeroid && komodo_appendACscriptpub() ) + if ( !didinit && height > KOMODO_EARLYTXID_HEIGHT && KOMODO_EARLYTXID != zeroid && komodo_appendACscriptpub() ) { fprintf(stderr, "appended CC_op_return to ASSETCHAINS_SCRIPTPUB.%s\n", ASSETCHAINS_SCRIPTPUB.c_str()); didinit = true; diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 001ee0dce..1ee3ef788 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -17,7 +17,7 @@ #define KOMODO_DEFS_H #include "komodo_nk.h" -#define KOMODO_EARLYTXID_HEIGHT 200 +#define KOMODO_EARLYTXID_HEIGHT 100 #define ASSETCHAINS_MINHEIGHT 128 #define ASSETCHAINS_MAX_ERAS 7 #define KOMODO_ELECTION_GAP 2000 diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 41fab362c..0821017ff 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2387,7 +2387,7 @@ void komodo_args(char *argv0) if ( strcmp("ILN",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - // CCDISABLEALL; + CCDISABLEALL; } if ( strcmp("OUR",ASSETCHAINS_SYMBOL) == 0 ) { diff --git a/src/miner.cpp b/src/miner.cpp index 55e2c708f..2e428c0dc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -665,7 +665,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { static bool didinit = false; - if ( !didinit && nHeight > 100 && KOMODO_EARLYTXID != zeroid && komodo_appendACscriptpub() ) + if ( !didinit && nHeight > KOMODO_EARLYTXID_HEIGHT && KOMODO_EARLYTXID != zeroid && komodo_appendACscriptpub() ) { fprintf(stderr, "appended ccopreturn to ASSETCHAINS_SCRIPTPUB.%s\n", ASSETCHAINS_SCRIPTPUB.c_str()); didinit = true; From 4bbc78d5275202e0fc7b976d26fccb807906be2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 15:17:25 -1100 Subject: [PATCH 585/659] NSPV_utxos2CCunspents --- src/cc/CCtx.cpp | 7 +++++++ src/komodo_nSPV_wallet.h | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 96b22adad..c29856d1c 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -325,9 +325,16 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else return("0"); } +void NSPV_CCunspents(std::vector > &unspentOutputs,char *coinaddr,bool ccflag); + void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool ccflag) { int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector > addresses; + if ( KOMODO_NSPV != 0 ) + { + NSPV_CCunspents(unspentOutputs,coinaddr,ccflag); + return; + } n = (int32_t)strlen(coinaddr); addrstr.resize(n+1); ptr = (char *)addrstr.data(); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 3dc4b23f0..2e883a439 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -442,4 +442,31 @@ int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total } else return(0); } +void NSPV_utxos2CCunspents(struct NSPV_utxosresp *ptr,std::vector > &outputs) +{ + CAddressUnspentKey key; CAddressUnspentValue value; int32_t i,type; uint160 hashBytes; std::string addrstr(ptr->coinaddr); + if ( ptr->utxos != NULL && ptr->numutxos > 0 ) + { + CBitcoinAddress address(addrstr); + if (address.GetIndexKey(hashBytes, type, ptr->CCflag) == 0) + return; + for (i = 0; i < ptr->numutxos; i ++) + { + key.type = type; + key.hashBytes = hashBytes; + key.txhash = ptr->utxos[i].txid; + key.index = ptr->utxos[i].vout; + value.satoshis = ptr->utxos[i].satoshis; + value.blockHeight = ptr->utxos[i].height; + outputs.push_back(std::make_pair(key, value)); + } + } +} + +void NSPV_CCunspents(std::vector > &outputs,char *coinaddr,bool ccflag) +{ + UniValue NSPV_addressutxos(coinaddr,ccflag); + NSPV_utxos2CCunspents(&NSPV_utxosresult,outputs); +} + #endif // KOMODO_NSPVWALLET_H From 44cd71622cb839b778c142aa0ef5882739fe7ade Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 15:23:20 -1100 Subject: [PATCH 586/659] +print --- src/komodo_nSPV_wallet.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 2e883a439..bf64657df 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -445,11 +445,15 @@ int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total void NSPV_utxos2CCunspents(struct NSPV_utxosresp *ptr,std::vector > &outputs) { CAddressUnspentKey key; CAddressUnspentValue value; int32_t i,type; uint160 hashBytes; std::string addrstr(ptr->coinaddr); + fprintf(stderr,"in converter\n"); if ( ptr->utxos != NULL && ptr->numutxos > 0 ) { CBitcoinAddress address(addrstr); - if (address.GetIndexKey(hashBytes, type, ptr->CCflag) == 0) + if ( address.GetIndexKey(hashBytes, type, ptr->CCflag) == 0 ) + { + fprintf(stderr,"couldnt get indexkey\n"); return; + } for (i = 0; i < ptr->numutxos; i ++) { key.type = type; From 88a5fd74ec1eee030bdf54afb481355804bb6976 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 15:25:12 -1100 Subject: [PATCH 587/659] Cast --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index bf64657df..94123941e 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -469,7 +469,7 @@ void NSPV_utxos2CCunspents(struct NSPV_utxosresp *ptr,std::vector > &outputs,char *coinaddr,bool ccflag) { - UniValue NSPV_addressutxos(coinaddr,ccflag); + UniValue NSPV_addressutxos(coinaddr,(int32_t)ccflag); NSPV_utxos2CCunspents(&NSPV_utxosresult,outputs); } From c893ef98995ee83a06090061e192f767c6a3434d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 15:26:17 -1100 Subject: [PATCH 588/659] Syntax --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 94123941e..8b638c28b 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -469,7 +469,7 @@ void NSPV_utxos2CCunspents(struct NSPV_utxosresp *ptr,std::vector > &outputs,char *coinaddr,bool ccflag) { - UniValue NSPV_addressutxos(coinaddr,(int32_t)ccflag); + NSPV_addressutxos(coinaddr,ccflag); NSPV_utxos2CCunspents(&NSPV_utxosresult,outputs); } From c84b5641c82cc8eae11e9f0f5de051c8f80eabb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 21:16:19 -1100 Subject: [PATCH 589/659] +print --- src/cc/CCtx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index c29856d1c..506b710e7 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -175,7 +175,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); - //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,cp->unspendableaddr2); + fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,cp->unspendableaddr2); //std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " for vin[" << i << "] satoshis=" << utxovalues[i] << std::endl; if( strcmp(destaddr, myaddr) == 0 ) { @@ -199,7 +199,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = unspendablepriv; cond = othercond; - //fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable); + fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable); } else if (strcmp(destaddr, unspendabletokensaddr) == 0) { From c63782f0ca4088cbd40e532074b6cca225d71921 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 21:21:26 -1100 Subject: [PATCH 590/659] +print --- src/cc/CCtx.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 506b710e7..ab4c55a3f 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -175,7 +175,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); - fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,cp->unspendableaddr2); + //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,cp->unspendableaddr2); //std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " for vin[" << i << "] satoshis=" << utxovalues[i] << std::endl; if( strcmp(destaddr, myaddr) == 0 ) { @@ -199,7 +199,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = unspendablepriv; cond = othercond; - fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable); + //fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable); } else if (strcmp(destaddr, unspendabletokensaddr) == 0) { @@ -280,13 +280,13 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) { - //int32_t z; - //for (z=0; z<32; z++) - // fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); - //fprintf(stderr," sighash, "); - //for (z=0; z<32; z++) - // fprintf(stderr,"%02x",privkey[z]); - //fprintf(stderr," signed with privkey\n"); + int32_t z; + for (z=0; z<32; z++) + fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); + fprintf(stderr," sighash, "); + for (z=0; z<32; z++) + fprintf(stderr,"%02x",privkey[z]); + fprintf(stderr," signed with privkey\n"); mtx.vin[i].scriptSig = CCSig(cond); } else From 93fb6f5f5121b0c6e3396dcbe13829e878f872fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 21:47:48 -1100 Subject: [PATCH 591/659] -print --- src/cc/CCinclude.h | 1 + src/cc/CCtx.cpp | 14 +-- src/rpc/crosschain.cpp | 23 ++-- src/rpc/testtransactions.cpp | 10 +- src/wallet/rpcwallet.cpp | 236 +++++++++++++++++------------------ 5 files changed, 143 insertions(+), 141 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 53a2d050f..5882a1355 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -56,6 +56,7 @@ one other technical note is that komodod has the insight-explorer extensions bui #define CC_BURNPUBKEY "02deaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead" #define CC_MAXVINS 1024 +#define CC_REQUIREMENTS_MSG (KOMMODO_NSPV!=0?"to use CC contracts you need to nspv_login first\n":"to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n") #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index ab4c55a3f..c29856d1c 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -280,13 +280,13 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) { - int32_t z; - for (z=0; z<32; z++) - fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); - fprintf(stderr," sighash, "); - for (z=0; z<32; z++) - fprintf(stderr,"%02x",privkey[z]); - fprintf(stderr," signed with privkey\n"); + //int32_t z; + //for (z=0; z<32; z++) + // fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); + //fprintf(stderr," sighash, "); + //for (z=0; z<32; z++) + // fprintf(stderr,"%02x",privkey[z]); + //fprintf(stderr," signed with privkey\n"); mtx.vin[i].scriptSig = CCSig(cond); } else diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index bf0dbea4c..8407439ff 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -854,6 +854,7 @@ UniValue importgatewayinfo(const UniValue& params, bool fHelp) return(ImportGatewayInfo(txid)); } + UniValue importgatewaybind(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); @@ -866,7 +867,7 @@ UniValue importgatewaybind(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 8) throw runtime_error("use \'importgatewaybind coin orcletxid M N pubkeys pubtype p2shtype wiftype [taddr]\' to bind an import gateway\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); CCerror = ""; coin = params[0].get_str(); oracletxid = Parseuint256(params[1].get_str().c_str()); @@ -919,7 +920,7 @@ UniValue importgatewaydeposit(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 9) throw runtime_error("use \'importgatewaydeposit bindtxid height coin burntxid nvout rawburntx rawproof destpub amount\' to import deposited coins\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); CCerror = ""; bindtxid = Parseuint256(params[0].get_str().c_str()); height = atoi(params[1].get_str().c_str()); @@ -962,7 +963,7 @@ UniValue importgatewaywithdraw(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 4) throw runtime_error("use \'importgatewaywithdraw bindtxid coin withdrawpub amount\' to burn imported coins and withdraw them on external chain\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); CCerror = ""; bindtxid = Parseuint256(params[0].get_str().c_str()); coin = params[1].get_str(); @@ -997,7 +998,7 @@ UniValue importgatewaypartialsign(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("importgatewayspartialsign txidaddr refcoin hex\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); txid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); parthex = params[2].get_str(); @@ -1020,7 +1021,7 @@ UniValue importgatewaycompletesigning(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("importgatewaycompletesigning withdrawtxid coin hex\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); withdrawtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); txhex = params[2].get_str(); @@ -1040,7 +1041,7 @@ UniValue importgatewaymarkdone(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("importgatewaymarkdone completesigningtx coin\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); completetxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); hex = ImportGatewayMarkDone(0,completetxid,coin); @@ -1059,7 +1060,7 @@ UniValue importgatewaypendingdeposits(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("importgatewaypendingdeposits bindtxid coin\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); return(ImportGatewayPendingDeposits(bindtxid,coin)); @@ -1071,7 +1072,7 @@ UniValue importgatewaypendingwithdraws(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("importgatewaypendingwithdraws bindtxid coin\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); return(ImportGatewayPendingWithdraws(bindtxid,coin)); @@ -1083,7 +1084,7 @@ UniValue importgatewayprocessed(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("importgatewayprocessed bindtxid coin\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); return(ImportGatewayProcessedWithdraws(bindtxid,coin)); @@ -1096,7 +1097,7 @@ UniValue importgatewayexternaladdress(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2) throw runtime_error("importgatewayexternaladdress bindtxid pubkey\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); pubkey = ParseHex(params[1].get_str().c_str()); return(ImportGatewayExternalAddress(bindtxid,pubkey)); @@ -1109,7 +1110,7 @@ UniValue importgatewaydumpprivkey(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2) throw runtime_error("importgatewaydumpprivkey bindtxid address\n"); if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); std::string strAddress = params[1].get_str(); CTxDestination dest = DecodeDestination(strAddress); diff --git a/src/rpc/testtransactions.cpp b/src/rpc/testtransactions.cpp index ddf7c8895..849300a62 100644 --- a/src/rpc/testtransactions.cpp +++ b/src/rpc/testtransactions.cpp @@ -61,7 +61,7 @@ UniValue test_ac(const UniValue& params, bool fHelp) if (fHelp || (params.size() != 4)) throw runtime_error("incorrect params\n"); if (ensure_CCrequirements(EVAL_HEIR) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); std::vector pubkey1; std::vector pubkey2; @@ -106,7 +106,7 @@ UniValue test_heirmarker(const UniValue& params, bool fHelp) if (fHelp || (params.size() != 1)) throw runtime_error("incorrect params\n"); if (ensure_CCrequirements(EVAL_HEIR) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); uint256 fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -137,7 +137,7 @@ UniValue test_burntx(const UniValue& params, bool fHelp) if (fHelp || (params.size() != 1)) throw runtime_error("incorrect params\n"); if (ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); uint256 tokenid = Parseuint256((char *)params[0].get_str().c_str()); @@ -230,7 +230,7 @@ UniValue test_pricesmarker(const UniValue& params, bool fHelp) if (fHelp || (params.size() != 1)) throw runtime_error("incorrect params\n"); if (ensure_CCrequirements(EVAL_PRICES) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); uint256 bettxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -265,4 +265,4 @@ void RegisterTesttransactionsRPCCommands(CRPCTable &tableRPC) { for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); -} \ No newline at end of file +} diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 49c419c3d..426baa1f7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5544,7 +5544,7 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("channelsaddress pubkey\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Channels",pubkey)); } @@ -5555,7 +5555,7 @@ UniValue cclibaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 2 ) throw runtime_error("cclibaddress [evalcode] [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() >= 1 ) { evalcode = atoi(params[0].get_str().c_str()); @@ -5576,7 +5576,7 @@ UniValue cclibinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("cclibinfo\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); cp = CCinit(&C,evalcode); return(CClib_info(cp)); } @@ -5591,7 +5591,7 @@ UniValue cclib(const UniValue& params, bool fHelp) if ( ASSETCHAINS_CCLIB.size() == 0 ) throw runtime_error("no -ac_cclib= specified\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); method = (char *)params[0].get_str().c_str(); @@ -5624,7 +5624,7 @@ UniValue payments_release(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("paymentsrelease \"[%22createtxid%22,amount,(skipminimum)]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); cp = CCinit(&C,EVAL_PAYMENTS); @@ -5637,7 +5637,7 @@ UniValue payments_fund(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("paymentsfund \"[%22createtxid%22,amount(,useopret)]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); cp = CCinit(&C,EVAL_PAYMENTS); @@ -5650,7 +5650,7 @@ UniValue payments_merge(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("paymentsmerge \"[%22createtxid%22]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); cp = CCinit(&C,EVAL_PAYMENTS); @@ -5663,7 +5663,7 @@ UniValue payments_txidopret(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("paymentstxidopret \"[allocation,%22scriptPubKey%22(,%22destopret%22)]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); cp = CCinit(&C,EVAL_PAYMENTS); @@ -5676,7 +5676,7 @@ UniValue payments_create(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("paymentscreate \"[lockedblocks,minamount,%22paytxid0%22,...,%22paytxidN%22]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); cp = CCinit(&C,EVAL_PAYMENTS); @@ -5689,7 +5689,7 @@ UniValue payments_airdrop(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("paymentsairdrop \"[lockedblocks,minamount,mintoaddress,top,bottom,fixedFlag,%22excludeAddress%22,...,%22excludeAddressN%22]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); cp = CCinit(&C,EVAL_PAYMENTS); @@ -5702,7 +5702,7 @@ UniValue payments_airdroptokens(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("payments_airdroptokens \"[%22tokenid%22,lockedblocks,minamount,mintoaddress,top,bottom,fixedFlag,%22excludePubKey%22,...,%22excludePubKeyN%22]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); cp = CCinit(&C,EVAL_PAYMENTS); @@ -5715,7 +5715,7 @@ UniValue payments_info(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("paymentsinfo \"[%22createtxid%22]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); cp = CCinit(&C,EVAL_PAYMENTS); @@ -5728,7 +5728,7 @@ UniValue payments_list(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 0 ) throw runtime_error("paymentslist\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); cp = CCinit(&C,EVAL_PAYMENTS); @@ -5742,7 +5742,7 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("oraclesaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Oracles",pubkey)); @@ -5756,7 +5756,7 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("pricesaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); result = CCaddress(cp,(char *)"Prices",pubkey); @@ -5778,7 +5778,7 @@ UniValue pegsaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("pegssaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Pegs",pubkey)); @@ -5791,7 +5791,7 @@ UniValue marmaraaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("Marmaraaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Marmara",pubkey)); @@ -5804,7 +5804,7 @@ UniValue paymentsaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("paymentsaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Payments",pubkey)); @@ -5817,7 +5817,7 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("gatewaysaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Gateways",pubkey)); @@ -5830,7 +5830,7 @@ UniValue heiraddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("heiraddress pubkey\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Heir",pubkey)); } @@ -5842,7 +5842,7 @@ UniValue lottoaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("lottoaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Lotto",pubkey)); @@ -5855,7 +5855,7 @@ UniValue FSMaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("FSMaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"FSM",pubkey)); @@ -5868,7 +5868,7 @@ UniValue auctionaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("auctionaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Auction",pubkey)); @@ -5881,7 +5881,7 @@ UniValue diceaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("diceaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Dice",pubkey)); @@ -5909,7 +5909,7 @@ UniValue rewardsaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("rewardsaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Rewards",pubkey)); @@ -5922,7 +5922,7 @@ UniValue assetsaddress(const UniValue& params, bool fHelp) if (fHelp || params.size() > 1) throw runtime_error("assetsaddress [pubkey]\n"); if (ensure_CCrequirements(0) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if (params.size() == 1) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp, (char *)"Assets", pubkey)); @@ -5935,7 +5935,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("tokenaddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Tokens", pubkey)); @@ -5948,7 +5948,7 @@ UniValue importgatewayaddress(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("importgatewayddress [pubkey]\n"); if ( ensure_CCrequirements(0) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"ImportGateway", pubkey)); @@ -5964,7 +5964,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) throw runtime_error("marmarapoolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements(EVAL_MARMARA) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); perc = atof(params[0].get_str().c_str()) / 100.; @@ -5984,7 +5984,7 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) throw runtime_error("marmarareceive senderpk amount currency matures batontxid\n"); } if ( ensure_CCrequirements(EVAL_MARMARA) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); memset(&batontxid,0,sizeof(batontxid)); @@ -6015,7 +6015,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) throw runtime_error("marmaraissue receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements(EVAL_MARMARA) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); receiverpub = ParseHex(params[0].get_str().c_str()); @@ -6040,7 +6040,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) throw runtime_error("marmaratransfer receiverpk amount currency matures approvaltxid\n"); } if ( ensure_CCrequirements(EVAL_MARMARA) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); receiverpub = ParseHex(params[0].get_str().c_str()); if (receiverpub.size()!= 33) { @@ -6066,7 +6066,7 @@ UniValue marmara_info(const UniValue& params, bool fHelp) throw runtime_error("marmarainfo firstheight lastheight minamount maxamount [currency issuerpk]\n"); } if ( ensure_CCrequirements(EVAL_MARMARA) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); firstheight = atol(params[0].get_str().c_str()); @@ -6098,7 +6098,7 @@ UniValue marmara_creditloop(const UniValue& params, bool fHelp) throw runtime_error("marmaracreditloop txid\n"); } if ( ensure_CCrequirements(EVAL_MARMARA) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6116,7 +6116,7 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) throw runtime_error("marmarasettlement batontxid\n"); } if ( ensure_CCrequirements(EVAL_MARMARA) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); batontxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6145,7 +6145,7 @@ UniValue channelslist(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("channelsinfo\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); return(ChannelsList()); @@ -6157,7 +6157,7 @@ UniValue channelsinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("channelsinfo [opentxid]\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); opentxid=zeroid; @@ -6175,7 +6175,7 @@ UniValue channelsopen(const UniValue& params, bool fHelp) if ( fHelp || params.size() < 3 || params.size() > 4) throw runtime_error("channelsopen destpubkey numpayments payment\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); destpub = ParseHex(params[0].get_str().c_str()); @@ -6217,7 +6217,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp) if ( fHelp || params.size() < 2 || params.size() >3 ) throw runtime_error("channelspayment opentxid amount [secret]\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); opentxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6248,7 +6248,7 @@ UniValue channelsclose(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("channelsclose opentxid\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); opentxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6269,7 +6269,7 @@ UniValue channelsrefund(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("channelsrefund opentxid closetxid\n"); if ( ensure_CCrequirements(EVAL_CHANNELS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); opentxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6290,7 +6290,7 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 6 || params.size() < 2 ) throw runtime_error("rewardscreatefunding name amount APR mindays maxdays mindeposit\n"); if ( ensure_CCrequirements(EVAL_REWARDS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); // default to OOT params @@ -6359,7 +6359,7 @@ UniValue rewardslock(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("rewardslock name fundingtxid amount\n"); if ( ensure_CCrequirements(EVAL_REWARDS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); @@ -6389,7 +6389,7 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("rewardsaddfunding name fundingtxid amount\n"); if ( ensure_CCrequirements(EVAL_REWARDS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); @@ -6424,7 +6424,7 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 3 || params.size() < 2 ) throw runtime_error("rewardsunlock name fundingtxid [txid]\n"); if ( ensure_CCrequirements(EVAL_REWARDS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); @@ -6452,7 +6452,7 @@ UniValue rewardslist(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("rewardslist\n"); if ( ensure_CCrequirements(EVAL_REWARDS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); return(RewardsList()); @@ -6464,7 +6464,7 @@ UniValue rewardsinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("rewardsinfo fundingtxid\n"); if ( ensure_CCrequirements(EVAL_REWARDS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6476,7 +6476,7 @@ UniValue gatewayslist(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("gatewayslist\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); return(GatewaysList()); @@ -6489,7 +6489,7 @@ UniValue gatewaysexternaladdress(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2) throw runtime_error("gatewaysexternaladdress bindtxid pubkey\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6504,7 +6504,7 @@ UniValue gatewaysdumpprivkey(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2) throw runtime_error("gatewaysdumpprivkey bindtxid address\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); std::string strAddress = params[1].get_str(); @@ -6529,7 +6529,7 @@ UniValue gatewaysinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("gatewaysinfo bindtxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6544,7 +6544,7 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp) if ( fHelp || params.size() < 10 ) throw runtime_error("gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s) pubtype p2shtype wiftype [taddr]\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6584,7 +6584,7 @@ UniValue gatewaysdeposit(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 9 ) throw runtime_error("gatewaysdeposit bindtxid height coin cointxid claimvout deposithex proof destpub amount\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6617,7 +6617,7 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 5 ) throw runtime_error("gatewaysclaim bindtxid coin deposittxid destpub amount\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6643,7 +6643,7 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 4 ) throw runtime_error("gatewayswithdraw bindtxid coin withdrawpub amount\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6668,7 +6668,7 @@ UniValue gatewayspartialsign(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("gatewayspartialsign txidaddr refcoin hex\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6690,7 +6690,7 @@ UniValue gatewayscompletesigning(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("gatewayscompletesigning withdrawtxid coin hex\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); withdrawtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6712,7 +6712,7 @@ UniValue gatewaysmarkdone(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("gatewaysmarkdone completesigningtx coin\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); completetxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6733,7 +6733,7 @@ UniValue gatewayspendingdeposits(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("gatewayspendingdeposits bindtxid coin\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6747,7 +6747,7 @@ UniValue gatewayspendingwithdraws(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("gatewayspendingwithdraws bindtxid coin\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6761,7 +6761,7 @@ UniValue gatewaysprocessed(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("gatewaysprocessed bindtxid coin\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6774,7 +6774,7 @@ UniValue oracleslist(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("oracleslist\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); return(OraclesList()); @@ -6786,7 +6786,7 @@ UniValue oraclesinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("oraclesinfo oracletxid\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6799,7 +6799,7 @@ UniValue oraclesfund(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("oraclesfund oracletxid\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6819,7 +6819,7 @@ UniValue oraclesregister(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("oraclesregister oracletxid datafee\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6841,7 +6841,7 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("oraclessubscribe oracletxid publisher amount\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6863,7 +6863,7 @@ UniValue oraclessample(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("oraclessample oracletxid txid\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); oracletxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6877,7 +6877,7 @@ UniValue oraclessamples(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("oraclessamples oracletxid batonaddress num\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6892,7 +6892,7 @@ UniValue oraclesdata(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("oraclesdata oracletxid hexstr\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6913,7 +6913,7 @@ UniValue oraclescreate(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("oraclescreate name description format\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = params[0].get_str(); @@ -6950,7 +6950,7 @@ UniValue FSMcreate(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("FSMcreate name states\n"); if ( ensure_CCrequirements(EVAL_FSM) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = params[0].get_str(); @@ -6970,7 +6970,7 @@ UniValue FSMlist(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("FSMlist\n"); if ( ensure_CCrequirements(EVAL_FSM) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); return(FSMList()); } @@ -6980,7 +6980,7 @@ UniValue FSMinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("FSMinfo fundingtxid\n"); if ( ensure_CCrequirements(EVAL_FSM) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); FSMtxid = Parseuint256((char *)params[0].get_str().c_str()); return(FSMInfo(FSMtxid)); } @@ -6991,7 +6991,7 @@ UniValue faucetinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 0 ) throw runtime_error("faucetinfo\n"); if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); return(FaucetInfo()); } @@ -7010,7 +7010,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) return(NSPV_spend(coinaddr,(char *)HexStr(v.scriptPubKey.begin()+1,v.scriptPubKey.end()-1).c_str(),funds)); } if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); if (funds > 0) { @@ -7030,7 +7030,7 @@ UniValue faucetget(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("faucetget\n"); if ( ensure_CCrequirements(EVAL_FAUCET) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); hex = FaucetGet(0); @@ -7059,7 +7059,7 @@ UniValue priceslist(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 0 && params.size() != 1) throw runtime_error("priceslist [all|open|closed]\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); uint32_t filter = 0; if (params.size() == 1) filter = pricesGetParam(params[0]); @@ -7074,7 +7074,7 @@ UniValue mypriceslist(const UniValue& params, bool fHelp) if (fHelp || params.size() != 0 && params.size() != 1) throw runtime_error("mypriceslist [all|open|closed]\n"); if (ensure_CCrequirements(EVAL_PRICES) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); uint32_t filter = 0; if (params.size() == 1) @@ -7090,7 +7090,7 @@ UniValue pricesinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 && params.size() != 2) throw runtime_error("pricesinfo bettxid [height]\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); bettxid = Parseuint256((char *)params[0].get_str().c_str()); height = 0; if (params.size() == 2) @@ -7104,7 +7104,7 @@ UniValue dicefund(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 6 ) throw runtime_error("dicefund name funds minbet maxbet maxodds timeoutblocks\n"); if ( ensure_CCrequirements(EVAL_DICE) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); @@ -7137,7 +7137,7 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("diceaddfunds name fundingtxid amount\n"); if ( ensure_CCrequirements(EVAL_DICE) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); @@ -7165,7 +7165,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 4 ) throw runtime_error("dicebet name fundingtxid amount odds\n"); if ( ensure_CCrequirements(EVAL_DICE) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); @@ -7197,7 +7197,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("dicefinish name fundingtxid bettxid\n"); if ( ensure_CCrequirements(EVAL_DICE) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); @@ -7232,7 +7232,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( fHelp || (params.size() != 2 && params.size() != 3) ) throw runtime_error("dicestatus name fundingtxid bettxid\n"); if ( ensure_CCrequirements(EVAL_DICE) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); @@ -7280,7 +7280,7 @@ UniValue dicelist(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("dicelist\n"); if ( ensure_CCrequirements(EVAL_DICE) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); return(DiceList()); } @@ -7290,7 +7290,7 @@ UniValue diceinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("diceinfo fundingtxid\n"); if ( ensure_CCrequirements(EVAL_DICE) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); return(DiceInfo(fundingtxid)); } @@ -7301,7 +7301,7 @@ UniValue tokenlist(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 0 ) throw runtime_error("tokenlist\n"); if ( ensure_CCrequirements(EVAL_TOKENS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); return(TokenList()); } @@ -7311,7 +7311,7 @@ UniValue tokeninfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("tokeninfo tokenid\n"); if ( ensure_CCrequirements(EVAL_TOKENS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); @@ -7324,7 +7324,7 @@ UniValue tokenorders(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 1 ) throw runtime_error("tokenorders tokenid\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); if (params.size() == 1) { @@ -7346,7 +7346,7 @@ UniValue mytokenorders(const UniValue& params, bool fHelp) if (fHelp || params.size() > 2) throw runtime_error("mytokenorders [evalcode]\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); @@ -7365,7 +7365,7 @@ UniValue tokenbalance(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 2 ) throw runtime_error("tokenbalance tokenid [pubkey]\n"); if ( ensure_CCrequirements(EVAL_TOKENS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); LOCK(cs_main); @@ -7407,7 +7407,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 4 || params.size() < 2 ) throw runtime_error("tokencreate name supply [description][data]\n"); if ( ensure_CCrequirements(EVAL_TOKENS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); @@ -7467,7 +7467,7 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3) throw runtime_error("tokentransfer tokenid destpubkey amount\n"); if ( ensure_CCrequirements(EVAL_TOKENS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); @@ -7503,7 +7503,7 @@ UniValue tokenconvert(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 4 ) throw runtime_error("tokenconvert evalcode tokenid pubkey amount\n"); if ( ensure_CCrequirements(EVAL_ASSETS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); evalcode = atoi(params[0].get_str().c_str()); @@ -7544,7 +7544,7 @@ UniValue tokenbid(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("tokenbid numtokens tokenid price\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); //numtokens = atoi(params[0].get_str().c_str()); @@ -7586,7 +7586,7 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("tokencancelbid tokenid bidtxid\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); @@ -7611,7 +7611,7 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("tokenfillbid tokenid bidtxid fillamount\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); @@ -7643,7 +7643,7 @@ UniValue tokenask(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("tokenask numtokens tokenid price\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); //numtokens = atoi(params[0].get_str().c_str()); @@ -7677,7 +7677,7 @@ UniValue tokenswapask(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 4 ) throw runtime_error("tokenswapask numtokens tokenid otherid price\n"); if ( ensure_CCrequirements(EVAL_ASSETS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); //numtokens = atoi(params[0].get_str().c_str()); @@ -7705,7 +7705,7 @@ UniValue tokencancelask(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 2 ) throw runtime_error("tokencancelask tokenid asktxid\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); @@ -7730,7 +7730,7 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) throw runtime_error("tokenfillask tokenid asktxid fillunits\n"); if (ensure_CCrequirements(EVAL_ASSETS) < 0 || ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); @@ -7770,7 +7770,7 @@ UniValue tokenfillswap(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 4 ) throw runtime_error("tokenfillswap tokenid otherid asktxid fillunits\n"); if ( ensure_CCrequirements(EVAL_ASSETS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); @@ -7851,7 +7851,7 @@ UniValue heirfund(const UniValue& params, bool fHelp) if (fHelp || params.size() != 6 && params.size() != 7) throw runtime_error("heirfund txfee funds heirname heirpubkey inactivitytime memo [tokenid]\n"); if (ensure_CCrequirements(EVAL_HEIR) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); @@ -7925,7 +7925,7 @@ UniValue heiradd(const UniValue& params, bool fHelp) if (fHelp || params.size() != 3) throw runtime_error("heiradd txfee funds fundingtxid\n"); if (ensure_CCrequirements(EVAL_HEIR) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); @@ -7959,7 +7959,7 @@ UniValue heirclaim(const UniValue& params, bool fHelp) if (fHelp || params.size() != 3) throw runtime_error("heirclaim txfee funds fundingtxid\n"); if (ensure_CCrequirements(EVAL_HEIR) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); @@ -7984,7 +7984,7 @@ UniValue heirinfo(const UniValue& params, bool fHelp) throw runtime_error("heirinfo fundingtxid\n"); // if ( ensure_CCrequirements(EVAL_HEIR) < 0 ) - // throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + // throw runtime_error(CC_REQUIREMENTS_MSG); fundingtxid = Parseuint256((char*)params[0].get_str().c_str()); return (HeirInfo(fundingtxid)); @@ -7996,7 +7996,7 @@ UniValue heirlist(const UniValue& params, bool fHelp) throw runtime_error("heirlist\n"); // if ( ensure_CCrequirements(EVAL_HEIR) < 0 ) - // throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + // throw runtime_error(CC_REQUIREMENTS_MSG); return (HeirList()); } @@ -8009,7 +8009,7 @@ UniValue pegscreate(const UniValue& params, bool fHelp) if ( fHelp || params.size()<3) throw runtime_error("pegscreate amount N bindtxid1 [bindtxid2 ...]\n"); if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); amount = atof((char *)params[0].get_str().c_str()) * COIN + 0.00000000499999; @@ -8039,7 +8039,7 @@ UniValue pegsfund(const UniValue& params, bool fHelp) if ( fHelp || params.size()!=3) throw runtime_error("pegsfund pegstxid tokenid amount\n"); if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256(params[0].get_str().c_str()); @@ -8062,7 +8062,7 @@ UniValue pegsget(const UniValue& params, bool fHelp) if ( fHelp || params.size()!=3) throw runtime_error("pegsget pegstxid tokenid amount\n"); if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256(params[0].get_str().c_str()); @@ -8085,7 +8085,7 @@ UniValue pegsredeem(const UniValue& params, bool fHelp) if ( fHelp || params.size()!=2) throw runtime_error("pegsredem pegstxid tokenid\n"); if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256(params[0].get_str().c_str()); @@ -8107,7 +8107,7 @@ UniValue pegsliquidate(const UniValue& params, bool fHelp) if ( fHelp || params.size()!=3) throw runtime_error("pegsliquidate pegstxid tokenid accounttxid\n"); if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256(params[0].get_str().c_str()); @@ -8130,7 +8130,7 @@ UniValue pegsexchange(const UniValue& params, bool fHelp) if ( fHelp || params.size()!=3) throw runtime_error("pegsliquidate pegstxid tokenid accounttxid\n"); if ( ensure_CCrequirements(EVAL_PEGS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256(params[0].get_str().c_str()); @@ -8153,7 +8153,7 @@ UniValue pegsaccounthistory(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("pegsaccounthistory pegstxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -8167,7 +8167,7 @@ UniValue pegsaccountinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("pegsaccountinfo pegstxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -8181,7 +8181,7 @@ UniValue pegsworstaccounts(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("pegsworstaccounts pegstxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -8195,7 +8195,7 @@ UniValue pegsinfo(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("pegsinfo pegstxid\n"); if ( ensure_CCrequirements(EVAL_GATEWAYS) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); pegstxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -8304,7 +8304,7 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) throw runtime_error("amount to burn, hexstring to send\n"); struct CCcontract_info *cp, C; UniValue ret(UniValue::VOBJ); if (ensure_CCrequirements(EVAL_ORACLES) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + throw runtime_error(CC_REQUIREMENTS_MSG); cp = CCinit(&C, EVAL_ORACLES); CAmount nAmount = AmountFromValue(params[0]); From c7ee536652548b1c26d912d40f180035f0e0a0d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 21:55:15 -1100 Subject: [PATCH 592/659] CC_REQ_MSG --- src/cc/CCinclude.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 5882a1355..24acc03e2 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -56,7 +56,7 @@ one other technical note is that komodod has the insight-explorer extensions bui #define CC_BURNPUBKEY "02deaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead" #define CC_MAXVINS 1024 -#define CC_REQUIREMENTS_MSG (KOMMODO_NSPV!=0?"to use CC contracts you need to nspv_login first\n":"to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n") +#define CC_REQUIREMENTS_MSG (KOMODO_NSPV!=0?"to use CC contracts you need to nspv_login first\n":"to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n") #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) From 8fc2650ff9fcb05de387318d85b822bfb68a54f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 22:44:49 -1100 Subject: [PATCH 593/659] msgHash --- src/cryptoconditions/src/cryptoconditions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index 9bbdfbd95..3763c867b 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -274,7 +274,7 @@ int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength, else memcpy(msgHash, msg, 32); if (!cc_secp256k1VerifyTreeMsg32(cond, msgHash)) { - fprintf(stderr,"cc_verify error C\n"); + fprintf(stderr,"cc_verify error C msgHash.%s\n",msgHash.GetHex().c_str()); return 0; } From 1904b96d92da7fd9541eb57df5be2cc247707d62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 22:54:25 -1100 Subject: [PATCH 594/659] Sighs --- src/cc/CCtx.cpp | 8 ++++---- src/cryptoconditions/src/cryptoconditions.c | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index c29856d1c..1351cdffb 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -280,10 +280,10 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) { - //int32_t z; - //for (z=0; z<32; z++) - // fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); - //fprintf(stderr," sighash, "); + int32_t z; + for (z=0; z<32; z++) + fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); + fprintf(stderr," sighash\n"); //for (z=0; z<32; z++) // fprintf(stderr,"%02x",privkey[z]); //fprintf(stderr," signed with privkey\n"); diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index 3763c867b..1aae52c9b 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -274,7 +274,10 @@ int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength, else memcpy(msgHash, msg, 32); if (!cc_secp256k1VerifyTreeMsg32(cond, msgHash)) { - fprintf(stderr,"cc_verify error C msgHash.%s\n",msgHash.GetHex().c_str()); + int32_t z; + for (z=0; z<32; z++) + fprintf(stderr,"%02x",msgHash[z]); + fprintf(stderr," msgHash, cc_verify error C\n"); return 0; } From 4f9165480a59e08183ce73dc7a557b9daa1884b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Jul 2019 23:55:14 -1100 Subject: [PATCH 595/659] +prints --- src/main.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 79822f93c..4f61549e2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1780,7 +1780,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"already in mempool\n"); return state.Invalid(false, REJECT_DUPLICATE, "already in mempool"); } - +fprintf(stderr,"addmempool 0\n"); // Node operator can choose to reject tx by number of transparent inputs static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), "size_t too small"); size_t limit = (size_t) GetArg("-mempooltxinputlimit", 0); @@ -1794,6 +1794,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } +fprintf(stderr,"addmempool 1\n"); auto verifier = libzcash::ProofVerifier::Strict(); if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,chainActive.LastTip()->GetHeight()+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) @@ -1811,7 +1812,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); } - // Coinbase is only valid in a block, not as a loose transaction +fprintf(stderr,"addmempool 2\n"); + // Coinbase is only valid in a block, not as a loose transaction if (tx.IsCoinBase()) { fprintf(stderr,"AcceptToMemoryPool coinbase as individual tx\n"); @@ -1833,6 +1835,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"AcceptToMemoryPool reject non-final\n"); return state.DoS(0, false, REJECT_NONSTANDARD, "non-final"); } +fprintf(stderr,"addmempool 3\n"); // Check for conflicts with in-memory transactions if (!fSkipExpiry) @@ -1861,6 +1864,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } } +fprintf(stderr,"addmempool 4\n"); { CCoinsView dummy; @@ -1960,6 +1964,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } } +fprintf(stderr,"addmempool 5\n"); // Grab the branch ID we expect this transaction to commit to. We don't // yet know if it does, but if the entry gets added to the mempool, then @@ -2022,6 +2027,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa LogPrint("mempool", errmsg.c_str()); return state.Error("AcceptToMemoryPool: " + errmsg); } +fprintf(stderr,"addmempool 6\n"); // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. @@ -2047,6 +2053,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa flag = 1; KOMODO_CONNECTING = (1<<30) + (int32_t)chainActive.LastTip()->GetHeight() + 1; } +fprintf(stderr,"addmempool 7\n"); if (!fSkipExpiry && !ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { if ( flag != 0 ) From 80a3be3604b4d952e720e8d91bcae4aa94cf8e70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 00:02:52 -1100 Subject: [PATCH 596/659] +print --- src/cryptoconditions/src/cryptoconditions.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index 1aae52c9b..12f973b97 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -272,12 +272,13 @@ int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength, unsigned char msgHash[32]; if (doHashMsg) sha256(msg, msgLength, msgHash); else memcpy(msgHash, msg, 32); + int32_t z; + for (z=0; z<32; z++) + fprintf(stderr,"%02x",msgHash[z]); + fprintf(stderr," msgHash msglen.%d\n",msgLength); if (!cc_secp256k1VerifyTreeMsg32(cond, msgHash)) { - int32_t z; - for (z=0; z<32; z++) - fprintf(stderr,"%02x",msgHash[z]); - fprintf(stderr," msgHash, cc_verify error C\n"); + fprintf(stderr," cc_verify error C\n"); return 0; } From 69a46d84ec13262c30bb656eef94979e4945890c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 00:26:13 -1100 Subject: [PATCH 597/659] +print --- src/cc/CCtx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 1351cdffb..c69d0e738 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -277,13 +277,13 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran return(""); } } - uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata); + uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL,utxovalues[i],consensusBranchId, &txdata); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) { int32_t z; for (z=0; z<32; z++) fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); - fprintf(stderr," sighash\n"); + fprintf(stderr," sighash [%d] %.8f %x\n",i,(double)utxovalues[i]/COIN,consensusBranchId); //for (z=0; z<32; z++) // fprintf(stderr,"%02x",privkey[z]); //fprintf(stderr," signed with privkey\n"); From 59ef159612fbb7b87bd746576bb5d85bca98898f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 00:33:02 -1100 Subject: [PATCH 598/659] +print --- src/komodo_nSPV_wallet.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 8b638c28b..0d763964a 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -437,6 +437,7 @@ int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total NSPV_utxosresp_purge(&ptr->U); NSPV_utxosresp_copy(&ptr->U,&NSPV_utxosresult); } + fprintf(stderr,"%s numutxos.%d\n",ptr->U.coinaddr,ptr->U.numutxos); memset(ptr->used,0,sizeof(ptr->used)); return(NSPV_addinputs(ptr->used,mtx,total,maxinputs,ptr->U.utxos,ptr->U.numutxos)); } else return(0); From 80fd6fee580ec4c4adfbcde5f4af5243113d6c30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 00:58:31 -1100 Subject: [PATCH 599/659] mtx.fOverwintered = true; mtx.nExpiryHeight = 0; mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; mtx.nVersion = SAPLING_TX_VERSION; --- src/consensus/upgrades.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index 3cd30399f..aea806dfc 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -97,7 +97,10 @@ int CurrentEpoch(int nHeight, const Consensus::Params& params) { return Consensus::BASE_SPROUT; } -uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) { +uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) +{ + if ( KOMODO_NSPV != 0 ) + return(SAPLING_TX_VERSION); return NetworkUpgradeInfo[CurrentEpoch(nHeight, params)].nBranchId; } From c9ec6d961dcccbb7a0581e0f98adf05216c6ac01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 01:00:10 -1100 Subject: [PATCH 600/659] Include --- src/consensus/upgrades.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index aea806dfc..3153284c0 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "consensus/upgrades.h" - +#include "komodo_nSPV_defs.h" /** * General information about each network upgrade. * Ordered by Consensus::UpgradeIndex. @@ -100,7 +100,7 @@ int CurrentEpoch(int nHeight, const Consensus::Params& params) { uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) { if ( KOMODO_NSPV != 0 ) - return(SAPLING_TX_VERSION); + return(NSPV_BRANCHID); return NetworkUpgradeInfo[CurrentEpoch(nHeight, params)].nBranchId; } From 8910b7c56f19a544ba2a2a21a8aa4054af64b404 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 01:01:32 -1100 Subject: [PATCH 601/659] #define NSPV_BRANCHID 0x76b809bb --- src/consensus/upgrades.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index 3153284c0..786e58510 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -18,7 +18,9 @@ ******************************************************************************/ #include "consensus/upgrades.h" -#include "komodo_nSPV_defs.h" +extern int32_t KOMODO_NSPV; +#define NSPV_BRANCHID 0x76b809bb + /** * General information about each network upgrade. * Ordered by Consensus::UpgradeIndex. From aa95a58f26bdd18f0d14c4b396e6fa8fc23cc331 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 01:14:25 -1100 Subject: [PATCH 602/659] Txheight --- src/cc/CCtx.cpp | 8 ++++---- src/komodo_nSPV_wallet.h | 1 - src/main.cpp | 26 ++++++++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index c69d0e738..768e34fe7 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -280,10 +280,10 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL,utxovalues[i],consensusBranchId, &txdata); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) { - int32_t z; - for (z=0; z<32; z++) - fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); - fprintf(stderr," sighash [%d] %.8f %x\n",i,(double)utxovalues[i]/COIN,consensusBranchId); + //int32_t z; + //for (z=0; z<32; z++) + // fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); + //fprintf(stderr," sighash [%d] %.8f %x\n",i,(double)utxovalues[i]/COIN,consensusBranchId); //for (z=0; z<32; z++) // fprintf(stderr,"%02x",privkey[z]); //fprintf(stderr," signed with privkey\n"); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 0d763964a..df0cb9a8d 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -446,7 +446,6 @@ int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total void NSPV_utxos2CCunspents(struct NSPV_utxosresp *ptr,std::vector > &outputs) { CAddressUnspentKey key; CAddressUnspentValue value; int32_t i,type; uint160 hashBytes; std::string addrstr(ptr->coinaddr); - fprintf(stderr,"in converter\n"); if ( ptr->utxos != NULL && ptr->numutxos > 0 ) { CBitcoinAddress address(addrstr); diff --git a/src/main.cpp b/src/main.cpp index 4f61549e2..4e2e4a9c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1780,7 +1780,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"already in mempool\n"); return state.Invalid(false, REJECT_DUPLICATE, "already in mempool"); } -fprintf(stderr,"addmempool 0\n"); +//fprintf(stderr,"addmempool 0\n"); // Node operator can choose to reject tx by number of transparent inputs static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), "size_t too small"); size_t limit = (size_t) GetArg("-mempooltxinputlimit", 0); @@ -1794,7 +1794,7 @@ fprintf(stderr,"addmempool 0\n"); return false; } } -fprintf(stderr,"addmempool 1\n"); +//fprintf(stderr,"addmempool 1\n"); auto verifier = libzcash::ProofVerifier::Strict(); if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,chainActive.LastTip()->GetHeight()+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) @@ -1812,7 +1812,7 @@ fprintf(stderr,"addmempool 1\n"); { return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); } -fprintf(stderr,"addmempool 2\n"); +//fprintf(stderr,"addmempool 2\n"); // Coinbase is only valid in a block, not as a loose transaction if (tx.IsCoinBase()) { @@ -1835,7 +1835,7 @@ fprintf(stderr,"addmempool 2\n"); //fprintf(stderr,"AcceptToMemoryPool reject non-final\n"); return state.DoS(0, false, REJECT_NONSTANDARD, "non-final"); } -fprintf(stderr,"addmempool 3\n"); +//fprintf(stderr,"addmempool 3\n"); // Check for conflicts with in-memory transactions if (!fSkipExpiry) @@ -1864,7 +1864,7 @@ fprintf(stderr,"addmempool 3\n"); } } } -fprintf(stderr,"addmempool 4\n"); +//fprintf(stderr,"addmempool 4\n"); { CCoinsView dummy; @@ -1964,7 +1964,7 @@ fprintf(stderr,"addmempool 4\n"); } } } -fprintf(stderr,"addmempool 5\n"); +//fprintf(stderr,"addmempool 5\n"); // Grab the branch ID we expect this transaction to commit to. We don't // yet know if it does, but if the entry gets added to the mempool, then @@ -2027,7 +2027,7 @@ fprintf(stderr,"addmempool 5\n"); LogPrint("mempool", errmsg.c_str()); return state.Error("AcceptToMemoryPool: " + errmsg); } -fprintf(stderr,"addmempool 6\n"); +//fprintf(stderr,"addmempool 6\n"); // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. @@ -2053,7 +2053,7 @@ fprintf(stderr,"addmempool 6\n"); flag = 1; KOMODO_CONNECTING = (1<<30) + (int32_t)chainActive.LastTip()->GetHeight() + 1; } -fprintf(stderr,"addmempool 7\n"); +//fprintf(stderr,"addmempool 7\n"); if (!fSkipExpiry && !ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { if ( flag != 0 ) @@ -2229,8 +2229,14 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo memset(&hashBlock,0,sizeof(hashBlock)); if ( KOMODO_NSPV != 0 ) { - int64_t rewardsum = 0; int32_t retval,vout = 0; - retval = NSPV_gettransaction(1,vout,hash,0,txOut,0,0,rewardsum); + int64_t rewardsum = 0; int32_t i,retval,txheight = 0,vout = 0; + for (i=0; i Date: Fri, 12 Jul 2019 01:35:59 -1100 Subject: [PATCH 603/659] ->myGetTransaction for nSPV virtualisation --- src/cc/CCassetstx.cpp | 12 ++++---- src/cc/CCtokens.cpp | 8 ++--- src/cc/auction.cpp | 2 +- src/cc/cclib.cpp | 4 +-- src/cc/channels.cpp | 24 +++++++-------- src/cc/dilithium.c | 2 +- src/cc/eval.cpp | 2 +- src/cc/fsm.cpp | 2 +- src/cc/gateways.cpp | 66 ++++++++++++++++++++-------------------- src/cc/heir.cpp | 6 ++-- src/cc/import.cpp | 6 ++-- src/cc/importgateway.cpp | 58 +++++++++++++++++------------------ src/cc/lotto.cpp | 8 ++--- src/cc/marmara.cpp | 18 +++++------ src/cc/oracles.cpp | 26 ++++++++-------- src/cc/payments.cpp | 2 +- src/cc/pegs.cpp | 48 ++++++++++++++--------------- src/cc/prices.cpp | 4 +-- src/cc/rewards.cpp | 12 ++++---- src/cc/sudoku.cpp | 6 ++-- src/rpc/crosschain.cpp | 4 +-- 21 files changed, 160 insertions(+), 160 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 0929591ff..6788cbf1f 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -39,7 +39,7 @@ UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode) txid = it->first.txhash; LOGSTREAM("ccassets", CCLOG_DEBUG2, stream << "addOrders() checking txid=" << txid.GetHex() << std::endl); - if ( GetTransaction(txid, ordertx, hashBlock, false) != 0 ) + if ( myGetTransaction(txid, ordertx, hashBlock) != 0 ) { // for logging: funcid = DecodeAssetOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey); if (ordertx.vout.size() > 0 && (funcid = DecodeAssetTokenOpRet(ordertx.vout[ordertx.vout.size()-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) != 0) @@ -273,7 +273,7 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in fprintf(stderr,"negative bidamount %lld, pricetotal %lld\n", (long long)bidamount, (long long)pricetotal); return(""); } - if (GetTransaction(assetid, vintx, hashBlock, false) == 0) + if (myGetTransaction(assetid, vintx, hashBlock) == 0) { fprintf(stderr,"cant find assetid\n"); return(""); @@ -470,7 +470,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if (GetTransaction(bidtxid, vintx, hashBlock, false) != 0) + if (myGetTransaction(bidtxid, vintx, hashBlock) != 0) { std::vector vopretNonfungible; GetNonfungibleData(assetid, vopretNonfungible); @@ -520,7 +520,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if (GetTransaction(asktxid, vintx, hashBlock, false) != 0) + if (myGetTransaction(asktxid, vintx, hashBlock) != 0) { std::vector vopretNonfungible; GetNonfungibleData(assetid, vopretNonfungible); @@ -594,7 +594,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f if (AddNormalinputs(mtx, mypk, 2*txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); - if (GetTransaction(bidtxid, vintx, hashBlock, false) != 0) + if (myGetTransaction(bidtxid, vintx, hashBlock) != 0) { bidamount = vintx.vout[bidvout].nValue; SetAssetOrigpubkey(origpubkey, origprice, vintx); @@ -697,7 +697,7 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a //if (AddNormalinputs(mtx, mypk, 2*txfee, 3) > 0) //{ //mask = ~((1LL << mtx.vin.size()) - 1); - if (GetTransaction(asktxid, vintx, hashBlock, false) != 0) + if (myGetTransaction(asktxid, vintx, hashBlock) != 0) { orig_assetoshis = vintx.vout[askvout].nValue; SetAssetOrigpubkey(origpubkey, total_nValue, vintx); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 0319af622..289549c36 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -654,7 +654,7 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C if (ivin != mtx.vin.size()) // that is, the tx.vout is already added to mtx.vin (in some previous calls) continue; - if (GetTransaction(vintxid, vintx, hashBlock, false) != 0) + if (myGetTransaction(vintxid, vintx, hashBlock) != 0) { Getscriptaddress(destaddr, vintx.vout[vout].scriptPubKey); if (strcmp(destaddr, tokenaddr) != 0 && @@ -920,7 +920,7 @@ int64_t GetTokenBalance(CPubKey pk, uint256 tokenid) // CCerror = strprintf("obsolete, cannot return correct value without eval"); // return 0; - if (GetTransaction(tokenid, tokentx, hashBlock, false) == 0) + if (myGetTransaction(tokenid, tokentx, hashBlock) == 0) { LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "cant find tokenid" << std::endl); CCerror = strprintf("cant find tokenid"); @@ -945,7 +945,7 @@ UniValue TokenInfo(uint256 tokenid) cpTokens = CCinit(&tokensCCinfo, EVAL_TOKENS); - if( !GetTransaction(tokenid, tokenbaseTx, hashBlock, false) ) + if( !myGetTransaction(tokenid, tokenbaseTx, hashBlock) ) { fprintf(stderr, "TokenInfo() cant find tokenid\n"); result.push_back(Pair("result", "error")); @@ -1031,7 +1031,7 @@ UniValue TokenList() cp = CCinit(&C, EVAL_TOKENS); auto addTokenId = [&](uint256 txid) { - if (GetTransaction(txid, vintx, hashBlock, false) != 0) { + if (myGetTransaction(txid, vintx, hashBlock) != 0) { if (vintx.vout.size() > 0 && DecodeTokenCreateOpRet(vintx.vout[vintx.vout.size() - 1].scriptPubKey, origpubkey, name, description) != 0) { result.push_back(txid.GetHex()); } diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 7521256c7..88d5134af 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -131,7 +131,7 @@ int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu // prevent dup if ( it->second.satoshis < 1000000 ) continue; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( (nValue= IsAuctionvout(cp,vintx,(int32_t)it->first.index)) > 0 ) { diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index ee52dadcf..dddd59f59 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -520,7 +520,7 @@ int64_t AddCClibInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK if ( it->second.satoshis < threshold || it->second.satoshis == txfee ) continue; // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( (nValue= IsCClibvout(cp,vintx,vout,cmpaddr)) >= 1000000 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { @@ -550,7 +550,7 @@ int64_t AddCClibtxfee(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe //char str[65]; fprintf(stderr,"%s check %s/v%d %.8f vs %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,(double)threshold/COIN); if ( it->second.satoshis < txfee ) continue; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( (nValue= IsCClibvout(cp,vintx,vout,coinaddr)) != 0 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 2d161675c..f88546b6e 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -416,7 +416,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C else marker=2; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) + if ( (int32_t)it->first.index==0 && myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts=tx.vout.size()) > 0) { if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && IsChannelsMarkervout(cp,tx,marker==1?srcpub:destpub,marker)>0 && @@ -517,7 +517,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) + if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) { CCerror = strprintf("invalid channel open txid"); LOGSTREAM("channelscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -555,7 +555,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && (change=funds-amount)>=0) { numpayments=amount/payment; - if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 && + if (myGetTransaction(prevtxid,prevTx,hashblock) != 0 && (numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tokenid, txid, srcpub, destpub, prevdepth, param2, param3)) != 0) && (funcid == 'P' || funcid=='O')) { @@ -642,7 +642,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) + if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) { CCerror = strprintf("invalid channel open txid"); LOGSTREAM("channelscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -702,7 +702,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if (GetTransaction(closetxid,channelCloseTx,hashblock,false) == 0) + if (myGetTransaction(closetxid,channelCloseTx,hashblock) == 0) { CCerror = strprintf("invalid channel close txid"); LOGSTREAM("channelscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -726,7 +726,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) LOGSTREAM("channelscc",CCLOG_INFO, stream << CCerror << std::endl); return (""); } - if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) + if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) { CCerror = strprintf("invalid channel open txid"); LOGSTREAM("channelscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -754,7 +754,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid,mypk)) !=0 && funds>0) { - if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && + if ((myGetTransaction(prevtxid,prevTx,hashblock) != 0) && (numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tokenid, txid, srcpub, destpub, param1, param2, param3) != 0) { mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,CC_MARKER_VALUE,mypk)); @@ -799,7 +799,7 @@ UniValue ChannelsList() txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second; - if ( (vout == 1 || vout == 2) && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + if ( (vout == 1 || vout == 2) && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 ) { if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O') { @@ -822,7 +822,7 @@ UniValue ChannelsInfo(uint256 channeltxid) cp = CCinit(&C,EVAL_CHANNELS); mypk = pubkey2pk(Mypubkey()); - if (GetTransaction(channeltxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && + if (myGetTransaction(channeltxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'O')) { GetCCaddress(cp,CCaddr,mypk); @@ -845,7 +845,7 @@ UniValue ChannelsInfo(uint256 channeltxid) SetCCtxids(addressIndex,CCaddr,true); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { - if (GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + if (myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 ) if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==channeltxid || tx.GetHash()==channeltxid)) txids.push_back(it->first.txhash); } @@ -861,7 +861,7 @@ UniValue ChannelsInfo(uint256 channeltxid) for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) { txid=*it; - if (txid!=prevtxid && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + if (txid!=prevtxid && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 ) { UniValue obj(UniValue::VOBJ); if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid) @@ -870,7 +870,7 @@ UniValue ChannelsInfo(uint256 channeltxid) } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid) { - if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && + if (myGetTransaction(opentxid,opentx,hashBlock) != 0 && (numvouts=opentx.vout.size()) > 0 && DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') { Getscriptaddress(str,tx.vout[3].scriptPubKey); diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 5dfa1deda..4a3813e61 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3354,7 +3354,7 @@ int64_t dilithium_inputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu //char str[65]; fprintf(stderr,"%s check %s/v%d %.8f vs %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,(double)threshold/COIN); if ( it->second.satoshis < threshold || it->second.satoshis == DILITHIUM_TXFEE ) continue; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && (numvouts= vintx.vout.size()) > 1 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) { if ( (nValue= IsCClibvout(cp,vintx,vout,cmpaddr)) > DILITHIUM_TXFEE && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index c580753cf..86065204a 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -129,7 +129,7 @@ bool Eval::GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &h { return(myGetTransaction(hash, txOut,hashBlock)); /*if (!myGetTransaction(hash, txOut,hashBlock)) { - return(GetTransaction(hash, txOut,hashBlock)); + return(myGetTransaction(hash, txOut,hashBlock)); } else return(true);*/ } diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index e44f85e47..dca2efd2d 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -133,7 +133,7 @@ int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey // prevent dup if ( it->second.satoshis < 1000000 ) continue; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( (nValue= IsFSMvout(cp,vintx,(int32_t)it->first.index)) > 0 ) { diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 00c80082b..c25a6e001 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -823,7 +823,7 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP std::vector > unspentOutputs; std::string refcoin,tmprefcoin; CPubKey withdrawpub,destpub; uint256 tokenid,txid,oracletxid,tmpbindtxid,tmptokenid,deposittxid,hashBlock; - if ( GetTransaction(bindtxid,bindtx,hashBlock,false) != 0 ) + if ( myGetTransaction(bindtxid,bindtx,hashBlock) != 0 ) { if ((numvouts=bindtx.vout.size())!=0 && DecodeGatewaysBindOpRet(depositaddr,bindtx.vout[numvouts-1].scriptPubKey,tokenid,refcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B') { @@ -839,7 +839,7 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { funcid=DecodeGatewaysOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey); if ((vout==0 && funcid=='B' && bindtxid==txid && total != 0 && maxinputs != 0) || @@ -932,7 +932,7 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - if ( GetTransaction(oracletxid,oracletx,hashBlock,false) == 0 || (numvouts= oracletx.vout.size()) <= 0 ) + if ( myGetTransaction(oracletxid,oracletx,hashBlock) == 0 || (numvouts= oracletx.vout.size()) <= 0 ) { CCerror = strprintf("cant find oracletxid %s",uint256_str(str,oracletxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -982,7 +982,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: txfee = 10000; mypk = pubkey2pk(Mypubkey()); LOGSTREAM("gatewayscc",CCLOG_DEBUG1, stream << "GatewaysDeposit ht." << height << " " << refcoin << " " << (double)amount/COIN << " numpks." << (int32_t)pubkeys.size() << std::endl); - if ( GetTransaction(bindtxid,bindtx,hashBlock,false) == 0 || (numvouts= bindtx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,bindtx,hashBlock) == 0 || (numvouts= bindtx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1059,7 +1059,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui txfee = 10000; mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1077,7 +1077,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - if ( GetTransaction(deposittxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(deposittxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find deposittxid %s",uint256_str(str,bindtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1138,7 +1138,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp, 0); - if( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1164,7 +1164,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; K=0; - if ( vout == 0 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && (funcid=DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P')) { if (funcid=='W' && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmptokenid,tmpbindtxid,coin,withdrawpub,tmpamount)=='W' @@ -1176,7 +1176,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin } else if (funcid=='P' && DecodeGatewaysPartialOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,signerpk,hex)=='P' && - GetTransaction(withdrawtxid,tx,hashBlock,false)!=0 && (numvouts=tx.vout.size())>0 && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmptokenid,tmpbindtxid,coin,withdrawpub,tmpamount)=='W' + myGetTransaction(withdrawtxid,tx,hashBlock)!=0 && (numvouts=tx.vout.size())>0 && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmptokenid,tmpbindtxid,coin,withdrawpub,tmpamount)=='W' && refcoin==coin && tmptokenid==tokenid && tmpbindtxid==bindtxid) { CCerror = strprintf("unable to create withdraw, another withdraw pending"); @@ -1220,7 +1220,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc txfee = 10000; mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); - if (GetTransaction(lasttxid,tx,hashBlock,false)==0 || (numvouts= tx.vout.size())<=0 + if (myGetTransaction(lasttxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0 || (funcid=DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey))==0 || (funcid!='W' && funcid!='P')) { CCerror = strprintf("can't find last tx %s",uint256_str(str,lasttxid)); @@ -1242,7 +1242,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1264,7 +1264,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(withdrawtxid,tmptx,hashBlock,false)==0 || (numvouts= tmptx.vout.size())<=0) + else if (myGetTransaction(withdrawtxid,tmptx,hashBlock)==0 || (numvouts= tmptx.vout.size())<=0) { CCerror = strprintf("can't find withdraw tx %s",uint256_str(str,withdrawtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1283,7 +1283,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 lasttxid,std::string refc LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1320,7 +1320,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string gatewayspk = GetUnspendable(cp,0); if ( txfee == 0 ) txfee = 10000; - if (GetTransaction(lasttxid,tx,hashBlock,false)==0 || (numvouts= tx.vout.size())<=0 + if (myGetTransaction(lasttxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0 || (funcid=DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey))==0 || (funcid!='W' && funcid!='P')) { CCerror = strprintf("invalid last txid %s",uint256_str(str,lasttxid)); @@ -1336,7 +1336,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1364,7 +1364,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(withdrawtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())==0) + else if (myGetTransaction(withdrawtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())==0) { CCerror = strprintf("invalid withdraw txid %s",uint256_str(str,withdrawtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1382,7 +1382,7 @@ std::string GatewaysCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1418,7 +1418,7 @@ std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string ref mypk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; - if (GetTransaction(completetxid,tx,hashBlock,false)==0 || (numvouts= tx.vout.size())<=0) + if (myGetTransaction(completetxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0) { CCerror = strprintf("invalid completesigning txid %s",uint256_str(str,completetxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1436,7 +1436,7 @@ std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string ref LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(withdrawtxid,tx,hashBlock,false)==0 || (numvouts= tx.vout.size())==0) + else if (myGetTransaction(withdrawtxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())==0) { CCerror = strprintf("invalid withdraw txid %s",uint256_str(str,withdrawtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1448,7 +1448,7 @@ std::string GatewaysMarkDone(uint64_t txfee,uint256 completetxid,std::string ref LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1485,7 +1485,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin) mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); _GetCCaddress(coinaddr,EVAL_GATEWAYS,mypk); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error",strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)))); @@ -1503,7 +1503,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if ( vout == 0 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && DecodeGatewaysDepositOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,publishers,txids,height,cointxid,claimvout,hex,proof,destpub,amount) == 'D' && tmpbindtxid==bindtxid && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { @@ -1540,7 +1540,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) gatewayspk = GetUnspendable(cp,0); _GetCCaddress(coinaddr,EVAL_GATEWAYS,gatewayspk); GetTokensCCaddress(cp,tokensaddr,gatewayspk); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error",strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)))); @@ -1567,7 +1567,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; K=0; - if ( vout == 0 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && (funcid=DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P') && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { if (funcid=='W') @@ -1576,7 +1576,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) } else if (funcid=='P') { - if (DecodeGatewaysPartialOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,signerpk,hex)!='P' || GetTransaction(withdrawtxid,tx,hashBlock,false)==0 + if (DecodeGatewaysPartialOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,signerpk,hex)!='P' || myGetTransaction(withdrawtxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0 || DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmptokenid,tmpbindtxid,coin,withdrawpub,amount)!='W' || refcoin!=coin || tmptokenid!=tokenid || tmpbindtxid!=bindtxid) continue; @@ -1628,7 +1628,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); _GetCCaddress(coinaddr,EVAL_GATEWAYS,gatewayspk); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error",strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)))); @@ -1654,10 +1654,10 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if ( vout == 0 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && DecodeGatewaysCompleteSigningOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,hex) == 'S' && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { - if (GetTransaction(withdrawtxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 + if (myGetTransaction(withdrawtxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmptokenid,bindtxid,coin,withdrawpub,amount) == 'W' || refcoin!=coin || tmptokenid!=tokenid) { UniValue obj(UniValue::VOBJ); @@ -1689,7 +1689,7 @@ UniValue GatewaysList() for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( vintx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,vintx.vout[vintx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 0 ) { @@ -1706,7 +1706,7 @@ UniValue GatewaysExternalAddress(uint256 bindtxid,CPubKey pubkey) std::string coin; int64_t numvouts,totalsupply; char str[65],addr[65],depositaddr[65]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector msigpubkeys; cp = CCinit(&C,EVAL_GATEWAYS); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error",strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)))); @@ -1730,7 +1730,7 @@ UniValue GatewaysDumpPrivKey(uint256 bindtxid,CKey key) std::string coin,priv; int64_t numvouts,totalsupply; char str[65],addr[65],depositaddr[65]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector msigpubkeys; cp = CCinit(&C,EVAL_GATEWAYS); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error",strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)))); @@ -1759,7 +1759,7 @@ UniValue GatewaysInfo(uint256 bindtxid) cp = CCinit(&C,EVAL_GATEWAYS); Gatewayspk = GetUnspendable(cp,0); GetTokensCCaddress(cp,gatewaystokens,Gatewayspk); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error",strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)))); @@ -1771,7 +1771,7 @@ UniValue GatewaysInfo(uint256 bindtxid) result.push_back(Pair("error",strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()))); return(result); } - if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) != 0 ) { result.push_back(Pair("result","success")); result.push_back(Pair("name","Gateways")); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index e047d1ab1..fc3a2f2fd 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -531,7 +531,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, //std::cerr << "Add1of2AddressInputs() txid=" << txid.GetHex() << std::endl; - if (GetTransaction(txid, heirtx, hashBlock, false) != 0) { + if (myGetTransaction(txid, heirtx, hashBlock) != 0) { uint256 tokenid; uint256 fundingTxidInOpret; uint8_t hasHeirSpendingBegunDummy; @@ -579,7 +579,7 @@ template int64_t LifetimeHeirContractFunds(struct CCcontract_info CTransaction heirtx; // TODO: check all funding tx should contain unspendable markers - if (GetTransaction(txid, heirtx, hashBlock, false) && heirtx.vout.size() > 0) { + if (myGetTransaction(txid, heirtx, hashBlock) && heirtx.vout.size() > 0) { uint256 tokenid; uint256 fundingTxidInOpret; uint8_t hasHeirSpendingBegunDummy; @@ -1232,7 +1232,7 @@ void _HeirList(struct CCcontract_info *cp, UniValue &result) //std::cerr << "HeirList() checking txid=" << txid.GetHex() << " vout=" << vout << '\n'; CTransaction fundingtx; - if (GetTransaction(txid, fundingtx, hashBlock, false)) { + if (myGetTransaction(txid, fundingtx, hashBlock)) { CPubKey ownerPubkey, heirPubkey; std::string heirName, memo; int64_t inactivityTimeSec; diff --git a/src/cc/import.cpp b/src/cc/import.cpp index aa2ea5d11..4a1978e8d 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -367,7 +367,7 @@ int32_t CheckGATEWAYimport(CTransaction importTx,CTransaction burnTx,std::string return(-1); } // check for valid burn from external coin blockchain and if valid return(0); - if (GetTransaction(bindtxid, bindtx, hashBlock, false) == 0 || (numvouts = bindtx.vout.size()) <= 0) + if (myGetTransaction(bindtxid, bindtx, hashBlock) == 0 || (numvouts = bindtx.vout.size()) <= 0) { LOGSTREAM("importgateway", CCLOG_INFO, stream << "CheckGATEWAYimport cant find bindtxid=" << bindtxid.GetHex() << std::endl); return(-1); @@ -397,7 +397,7 @@ int32_t CheckGATEWAYimport(CTransaction importTx,CTransaction burnTx,std::string LOGSTREAM("importgateway", CCLOG_INFO, stream << "CheckGATEWAYimport bindtx not yet confirmed/notarized" << std::endl); return(-1); } - else if (GetTransaction(oracletxid, oracletx, hashBlock, false) == 0 || (numvouts = oracletx.vout.size()) <= 0) + else if (myGetTransaction(oracletxid, oracletx, hashBlock) == 0 || (numvouts = oracletx.vout.size()) <= 0) { LOGSTREAM("importgateway", CCLOG_INFO, stream << "CheckGATEWAYimport cant find oracletxid=" << oracletxid.GetHex() << std::endl); return(-1); @@ -417,7 +417,7 @@ int32_t CheckGATEWAYimport(CTransaction importTx,CTransaction burnTx,std::string for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,regtx,hashBlock,false) != 0 && regtx.vout.size() > 0 + if ( myGetTransaction(txid,regtx,hashBlock) != 0 && regtx.vout.size() > 0 && DecodeOraclesOpRet(regtx.vout[regtx.vout.size()-1].scriptPubKey,tmporacletxid,regpk,datafee) == 'R' && oracletxid == tmporacletxid ) { pubkeys.push_back(regpk); diff --git a/src/cc/importgateway.cpp b/src/cc/importgateway.cpp index eff7bc287..e5590bb3d 100644 --- a/src/cc/importgateway.cpp +++ b/src/cc/importgateway.cpp @@ -525,7 +525,7 @@ std::string ImportGatewayBind(uint64_t txfee,std::string coin,uint256 oracletxid LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - if ( GetTransaction(oracletxid,oracletx,hashBlock,false) == 0 || (numvouts= oracletx.vout.size()) <= 0 ) + if ( myGetTransaction(oracletxid,oracletx,hashBlock) == 0 || (numvouts= oracletx.vout.size()) <= 0 ) { CCerror = strprintf("cant find oracletxid %s",uint256_str(str,oracletxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -581,7 +581,7 @@ std::string ImportGatewayDeposit(uint64_t txfee,uint256 bindtxid,int32_t height, return std::string(""); } LOGSTREAM("importgateway",CCLOG_DEBUG1, stream << "ImportGatewayDeposit ht." << height << " " << refcoin << " " << (double)amount/COIN << " numpks." << (int32_t)pubkeys.size() << std::endl); - if ( GetTransaction(bindtxid,bindtx,hashBlock,false) == 0 || (numvouts= bindtx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,bindtx,hashBlock) == 0 || (numvouts= bindtx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -651,7 +651,7 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re mypk = pubkey2pk(Mypubkey()); importgatewaypk = GetUnspendable(cp, 0); - if( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -677,7 +677,7 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; K=0; - if ( vout == 0 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && (funcid=DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P')) { if (funcid=='W' && DecodeImportGatewayWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,withdrawpub,tmpamount)=='W' @@ -689,7 +689,7 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re } else if (funcid=='P' && DecodeImportGatewayPartialOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,signerpk,hex)=='P' && - GetTransaction(withdrawtxid,tx,hashBlock,false)!=0 && (numvouts=tx.vout.size())>0 && DecodeImportGatewayWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,withdrawpub,tmpamount)=='W' + myGetTransaction(withdrawtxid,tx,hashBlock)!=0 && (numvouts=tx.vout.size())>0 && DecodeImportGatewayWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,withdrawpub,tmpamount)=='W' && refcoin==coin && tmpbindtxid==bindtxid) { CCerror = strprintf("unable to create withdraw, another withdraw pending"); @@ -722,7 +722,7 @@ std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string txfee = 10000; mypk = pubkey2pk(Mypubkey()); importgatewaypk = GetUnspendable(cp,0); - if (GetTransaction(lasttxid,tx,hashBlock,false)==0 || (numvouts= tx.vout.size())<=0 + if (myGetTransaction(lasttxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0 || (funcid=DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey))==0 || (funcid!='W' && funcid!='P')) { CCerror = strprintf("can't find last tx %s",uint256_str(str,lasttxid)); @@ -744,7 +744,7 @@ std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -766,7 +766,7 @@ std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(withdrawtxid,tmptx,hashBlock,false)==0 || (numvouts= tmptx.vout.size())<=0) + else if (myGetTransaction(withdrawtxid,tmptx,hashBlock)==0 || (numvouts= tmptx.vout.size())<=0) { CCerror = strprintf("can't find withdraw tx %s",uint256_str(str,withdrawtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -785,7 +785,7 @@ std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -822,7 +822,7 @@ std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::st importgatewaypk = GetUnspendable(cp,0); if ( txfee == 0 ) txfee = 10000; - if (GetTransaction(lasttxid,tx,hashBlock,false)==0 || (numvouts= tx.vout.size())<=0 + if (myGetTransaction(lasttxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0 || (funcid=DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey))==0 || (funcid!='W' && funcid!='P')) { CCerror = strprintf("invalid last txid %s",uint256_str(str,lasttxid)); @@ -838,7 +838,7 @@ std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::st LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -866,7 +866,7 @@ std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::st LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(withdrawtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())==0) + else if (myGetTransaction(withdrawtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())==0) { CCerror = strprintf("invalid withdraw txid %s",uint256_str(str,withdrawtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -884,7 +884,7 @@ std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::st LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tmptx,hashBlock)==0 || (numvouts=tmptx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -920,7 +920,7 @@ std::string ImportGatewayMarkDone(uint64_t txfee,uint256 completetxid,std::strin mypk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; - if (GetTransaction(completetxid,tx,hashBlock,false)==0 || (numvouts= tx.vout.size())<=0) + if (myGetTransaction(completetxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0) { CCerror = strprintf("invalid completesigning txid %s",uint256_str(str,completetxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -938,7 +938,7 @@ std::string ImportGatewayMarkDone(uint64_t txfee,uint256 completetxid,std::strin LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(withdrawtxid,tx,hashBlock,false)==0 || (numvouts= tx.vout.size())==0) + else if (myGetTransaction(withdrawtxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())==0) { CCerror = strprintf("invalid withdraw txid %s",uint256_str(str,withdrawtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -950,7 +950,7 @@ std::string ImportGatewayMarkDone(uint64_t txfee,uint256 completetxid,std::strin LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - else if (GetTransaction(bindtxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + else if (myGetTransaction(bindtxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -987,7 +987,7 @@ UniValue ImportGatewayPendingDeposits(uint256 bindtxid,std::string refcoin) mypk = pubkey2pk(Mypubkey()); importgatewaypk = GetUnspendable(cp,0); _GetCCaddress(coinaddr,EVAL_IMPORTGATEWAY,mypk); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -1005,7 +1005,7 @@ UniValue ImportGatewayPendingDeposits(uint256 bindtxid,std::string refcoin) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if ( vout == 0 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && DecodeImportGatewayDepositOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,publishers,txids,height,burntxid,claimvout,hex,proof,destpub,amount) == 'D' && tmpbindtxid==bindtxid && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { @@ -1041,7 +1041,7 @@ UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin) mypk = pubkey2pk(Mypubkey()); importgatewaypk = GetUnspendable(cp,0); _GetCCaddress(coinaddr,EVAL_IMPORTGATEWAY,importgatewaypk); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -1068,7 +1068,7 @@ UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin) vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; K=0; - if ( vout == 0 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && (funcid=DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P') && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { if (funcid=='W') @@ -1077,7 +1077,7 @@ UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin) } else if (funcid=='P') { - if (DecodeImportGatewayPartialOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,signerpk,hex)!='P' || GetTransaction(withdrawtxid,tx,hashBlock,false)==0 + if (DecodeImportGatewayPartialOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,signerpk,hex)!='P' || myGetTransaction(withdrawtxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0 || DecodeImportGatewayWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,withdrawpub,amount)!='W' || refcoin!=coin || tmpbindtxid!=bindtxid) continue; @@ -1129,7 +1129,7 @@ UniValue ImportGatewayProcessedWithdraws(uint256 bindtxid,std::string refcoin) mypk = pubkey2pk(Mypubkey()); importgatewaypk = GetUnspendable(cp,0); _GetCCaddress(coinaddr,EVAL_IMPORTGATEWAY,importgatewaypk); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -1155,10 +1155,10 @@ UniValue ImportGatewayProcessedWithdraws(uint256 bindtxid,std::string refcoin) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if ( vout == 0 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && DecodeImportGatewayCompleteSigningOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,hex) == 'S' && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { - if (GetTransaction(withdrawtxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size())>0 + if (myGetTransaction(withdrawtxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && DecodeImportGatewayWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxid,coin,withdrawpub,amount) == 'W' || refcoin!=coin) { UniValue obj(UniValue::VOBJ); @@ -1192,7 +1192,7 @@ UniValue ImportGatewayList() for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( vintx.vout.size() > 0 && DecodeImportGatewayBindOpRet(burnaddr,vintx.vout[vintx.vout.size()-1].scriptPubKey,coin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 0 ) { @@ -1209,7 +1209,7 @@ UniValue ImportGatewayExternalAddress(uint256 bindtxid,CPubKey pubkey) std::string coin; int64_t numvouts; char str[65],addr[65],burnaddr[65]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector msigpubkeys; cp = CCinit(&C,EVAL_IMPORTGATEWAY); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -1233,7 +1233,7 @@ UniValue ImportGatewayDumpPrivKey(uint256 bindtxid,CKey key) std::string coin,priv; int64_t numvouts; char str[65],addr[65],burnaddr[65]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector msigpubkeys; cp = CCinit(&C,EVAL_IMPORTGATEWAY); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -1262,7 +1262,7 @@ UniValue ImportGatewayInfo(uint256 bindtxid) cp = CCinit(&C,EVAL_IMPORTGATEWAY); ImportGatewaypk = GetUnspendable(cp,0); GetTokensCCaddress(cp,gatewaystokens,ImportGatewaypk); - if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); @@ -1274,7 +1274,7 @@ UniValue ImportGatewayInfo(uint256 bindtxid) LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 ) + if ( myGetTransaction(bindtxid,tx,hashBlock) != 0 ) { result.push_back(Pair("result","success")); result.push_back(Pair("name","ImportGateway")); diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index f873b3881..e8466bd88 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -173,7 +173,7 @@ int64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK // prevent dup if ( it->second.satoshis < COIN ) continue; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( (nValue= IsLottovout(cp,vintx,(int32_t)it->first.index)) > 0 ) { @@ -214,7 +214,7 @@ int64_t LottoPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,u { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { // need to implement this! if ( (funcid= DecodeLottoOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) == 'F' || funcid == 'T' ) { @@ -233,7 +233,7 @@ int64_t LottoPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,u UniValue LottoInfo(uint256 lottoid) { UniValue result(UniValue::VOBJ); uint256 hashBlock,hentropy; CTransaction vintx; uint64_t lockedfunds,sbits; int32_t ticketsize,odds,firstheight,period; CPubKey lottopk; struct CCcontract_info *cp,C; char str[67],numstr[65]; - if ( GetTransaction(lottoid,vintx,hashBlock,false) == 0 ) + if ( myGetTransaction(lottoid,vintx,hashBlock) == 0 ) { fprintf(stderr,"cant find lottoid\n"); result.push_back(Pair("result","error")); @@ -270,7 +270,7 @@ UniValue LottoList() for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( vintx.vout.size() > 0 && DecodeLottoFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,sbits,ticketsize,odds,firstheight,period,hentropy) == 'F' ) { diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f0d55eaf4..e28566079 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -360,7 +360,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, txid = it->first.txhash; vout = (int32_t)it->first.index; //fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) { @@ -399,7 +399,7 @@ int64_t AddMarmarainputs(CMutableTransaction &mtx,std::vector &pubkeys, vout = (int32_t)it->first.index; if ( it->second.satoshis < threshold ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht)) == 'C' || funcid == 'P' || funcid == 'L' ) { @@ -468,7 +468,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) vout = (int32_t)it->first.index; if ( (nValue= it->second.satoshis) < threshold ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && vout < numvouts && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { if ( (funcid= DecodeMaramaraCoinbaseOpRet(tx.vout[numvouts-1].scriptPubKey,pk,ht,unlockht)) == 'C' || funcid == 'P' || funcid == 'L' ) { @@ -516,7 +516,7 @@ int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &mtx) uint256 txid,hashBlock; uint8_t *ptr; int32_t i,siglen,vout,numvouts; CTransaction tx; std::string rawtx; CPubKey mypk; std::vector pubkeys; struct CCcontract_info *cp,C; uint64_t txfee; txfee = 10000; vout = mtx.vin[0].prevout.n; - if ( GetTransaction(mtx.vin[0].prevout.hash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 && vout < numvouts ) + if ( myGetTransaction(mtx.vin[0].prevout.hash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 && vout < numvouts ) { cp = CCinit(&C,EVAL_MARMARA); mypk = pubkey2pk(Mypubkey()); @@ -553,7 +553,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) height = chainActive.LastTip()->GetHeight(); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) { - if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && (numvouts= batontx.vout.size()) > 1 ) + if ( myGetTransaction(batontxid,batontx,hashBlock) != 0 && (numvouts= batontx.vout.size()) > 1 ) { if ( (funcid= MarmaraDecodeLoopOpret(batontx.vout[numvouts-1].scriptPubKey,refcreatetxid,pk,refamount,refmatures,refcurrency)) != 0 ) { @@ -593,7 +593,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) pubkeys.push_back(mypk); for (i=1; i 1 ) + if ( myGetTransaction(creditloop[i],tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { @@ -674,7 +674,7 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc txid = it->first.txhash; vout = (int32_t)it->first.index; //fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); - if ( vout == 1 && GetTransaction(txid,tx,hashBlock,false) != 0 ) + if ( vout == 1 && myGetTransaction(txid,tx,hashBlock) != 0 ) { if ( tx.IsCoinBase() == 0 && (numvouts= tx.vout.size()) > 2 && tx.vout[numvouts - 1].nValue == 0 ) { @@ -814,7 +814,7 @@ UniValue MarmaraCreditloop(uint256 txid) cp = CCinit(&C,EVAL_MARMARA); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,txid)) > 0 ) { - if ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) + if ( myGetTransaction(batontxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { result.push_back(Pair("result",(char *)"success")); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(Mypubkey())) << OP_CHECKSIG); @@ -886,7 +886,7 @@ UniValue MarmaraCreditloop(uint256 txid) } for (i=0; i 1 ) + if ( myGetTransaction(creditloop[i],tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { if ( (funcid= MarmaraDecodeLoopOpret(tx.vout[numvouts-1].scriptPubKey,createtxid,pk,amount,matures,currency)) != 0 ) { diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index bdd01ccfa..5056ccade 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -759,7 +759,7 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint txid = it->first.txhash; vout = (int32_t)it->first.index; //char str[65]; fprintf(stderr,"oracle check %s/v%d\n",uint256_str(str,txid),vout); - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && (numvouts=vintx.vout.size()-1)>0) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 && (numvouts=vintx.vout.size()-1)>0) { if ((funcid=DecodeOraclesOpRet(vintx.vout[numvouts].scriptPubKey,tmporacletxid,tmppk,tmpnum))!=0 && (funcid=='S' || funcid=='D')) { @@ -795,7 +795,7 @@ int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubK for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,subtx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,subtx,hashBlock) != 0 ) { if ( subtx.vout.size() > 0 && DecodeOraclesOpRet(subtx.vout[subtx.vout.size()-1].scriptPubKey,subtxid,pk,num) == 'S' && subtxid == oracletxid && pk == publisher ) { @@ -818,7 +818,7 @@ int64_t AddMyOraclesFunds(struct CCcontract_info *cp,CMutableTransaction &mtx,CP txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = it->second.satoshis; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && (numvouts=vintx.vout.size())>0) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 && (numvouts=vintx.vout.size())>0) { if ((funcid=DecodeOraclesOpRet(vintx.vout[numvouts-1].scriptPubKey,tmporacletxid,tmppk,tmpamount))!=0 && funcid=='F' && tmppk==pk && tmporacletxid==oracletxid && tmpamount==nValue && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout)==0) @@ -986,7 +986,7 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector da fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - if ( GetTransaction(oracletxid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 ) + if ( myGetTransaction(oracletxid,tx,hashBlock) != 0 && (numvouts=tx.vout.size()) > 0 ) { if ( DecodeOraclesCreateOpRet(tx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' ) { @@ -1061,11 +1061,11 @@ UniValue OracleDataSample(uint256 reforacletxid,uint256 txid) CPubKey pk; std::string name,description,format; int32_t numvouts; std::vector data; char str[67], *formatstr = 0; result.push_back(Pair("result","success")); - if ( GetTransaction(reforacletxid,oracletx,hashBlock,false) != 0 && (numvouts=oracletx.vout.size()) > 0 ) + if ( myGetTransaction(reforacletxid,oracletx,hashBlock) != 0 && (numvouts=oracletx.vout.size()) > 0 ) { if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' ) { - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size()) > 0 ) { if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid ) { @@ -1094,7 +1094,7 @@ UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num) std::vector > addressIndex; int64_t nValue; result.push_back(Pair("result","success")); - if ( GetTransaction(reforacletxid,oracletx,hashBlock,false) != 0 && (numvouts=oracletx.vout.size()) > 0 ) + if ( myGetTransaction(reforacletxid,oracletx,hashBlock) != 0 && (numvouts=oracletx.vout.size()) > 0 ) { if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' ) { @@ -1122,7 +1122,7 @@ UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num) txid=it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second; - if (vout==1 && nValue==10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 ) + if (vout==1 && nValue==10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size()) > 0 ) { if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid ) { @@ -1155,14 +1155,14 @@ UniValue OracleInfo(uint256 origtxid) cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,origtxid); - if ( GetTransaction(origtxid,tx,hashBlock,false) == 0 ) + if ( myGetTransaction(origtxid,tx,hashBlock) == 0 ) { fprintf(stderr,"cant find oracleid\n"); result.push_back(Pair("result","error")); result.push_back(Pair("error","cant find oracleid")); return(result); } - if ( GetTransaction(origtxid,tx,hashBlock,false) != 0 ) + if ( myGetTransaction(origtxid,tx,hashBlock) != 0 ) { if ( tx.vout.size() > 0 && DecodeOraclesCreateOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,name,description,format) == 'C' ) { @@ -1177,7 +1177,7 @@ UniValue OracleInfo(uint256 origtxid) { txid = it->first.txhash; height = (int32_t)it->second.blockHeight; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && DecodeOraclesOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R' && oracletxid == origtxid ) { if (publishers.find(pk)==publishers.end() || height>publishers[pk].second) @@ -1189,7 +1189,7 @@ UniValue OracleInfo(uint256 origtxid) } for (std::map>::iterator it = publishers.begin(); it != publishers.end(); ++it) { - if ( GetTransaction(it->second.first,tx,hashBlock,false) != 0 && DecodeOraclesOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R') + if ( myGetTransaction(it->second.first,tx,hashBlock) != 0 && DecodeOraclesOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R') { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("publisher",pubkey33_str(str,(uint8_t *)pk.begin()))); @@ -1222,7 +1222,7 @@ UniValue OraclesList() for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,createtx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,createtx,hashBlock) != 0 ) { if ( createtx.vout.size() > 0 && DecodeOraclesCreateOpRet(createtx.vout[createtx.vout.size()-1].scriptPubKey,name,description,format) == 'C' ) { diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index be4d63271..17507a80e 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -559,7 +559,7 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract txid = it->first.txhash; vout = (int32_t)it->first.index; //fprintf(stderr,"iter.%d %s/v%d %s\n",iter,txid.GetHex().c_str(),vout,coinaddr); - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( (nValue= IsPaymentsvout(cp,vintx,vout,coinaddr,ccopret)) > PAYMENTS_TXFEE && nValue >= threshold && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 96c41b9ff..4c3d659ae 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -382,7 +382,7 @@ int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe txid = it->first.txhash; vout = (int32_t)it->first.index; // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if (myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { @@ -413,7 +413,7 @@ int64_t AddPegsTokenInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,u txid = it->first.txhash; vout = (int32_t)it->first.index; // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if (myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 && DecodePegsOpRet(vintx,tmppegstxid,tmptokenid)!=0 && tmppegstxid==pegstxid && tmptokenid==tokenid) { @@ -521,7 +521,7 @@ double PegsGetTokenPrice(uint256 tokenid) int64_t *tokensyn,*btcusd; double price; CTransaction tokentx; uint256 hashBlock; std::string name,desc; std::vector vorigpubkey; int32_t numvouts; - if (GetTransaction(tokenid,tokentx,hashBlock,false)!=0 && (numvouts=tokentx.vout.size())>0 && DecodeTokenCreateOpRet(tokentx.vout[numvouts-1].scriptPubKey,vorigpubkey,name,desc)=='c') + if (myGetTransaction(tokenid,tokentx,hashBlock)!=0 && (numvouts=tokentx.vout.size())>0 && DecodeTokenCreateOpRet(tokentx.vout[numvouts-1].scriptPubKey,vorigpubkey,name,desc)=='c') { tokensyn = (int64_t *)calloc(sizeof(*tokensyn) * 3, 1 + PRICES_DAYWINDOW * 2 + PRICES_SMOOTHWIDTH); btcusd = (int64_t *)calloc(sizeof(*btcusd) * 3, 1 + PRICES_DAYWINDOW * 2 + PRICES_SMOOTHWIDTH); @@ -539,7 +539,7 @@ std::string PegsGetTokenName(uint256 tokenid) { CTransaction tokentx; uint256 hashBlock; std::string name,desc; std::vector vorigpubkey; int32_t numvouts; - if (GetTransaction(tokenid,tokentx,hashBlock,false)!=0 && (numvouts=tokentx.vout.size())>0 && DecodeTokenCreateOpRet(tokentx.vout[numvouts-1].scriptPubKey,vorigpubkey,name,desc)=='c') + if (myGetTransaction(tokenid,tokentx,hashBlock,false)!=0 && (numvouts=tokentx.vout.size())>0 && DecodeTokenCreateOpRet(tokentx.vout[numvouts-1].scriptPubKey,vorigpubkey,name,desc)=='c') { return (name); } @@ -555,7 +555,7 @@ double PegsGetAccountRatio(uint256 pegstxid,uint256 tokenid,uint256 accounttxid) std::pair account; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_PEGS); - if (GetTransaction(accounttxid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + if (myGetTransaction(accounttxid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && (funcid=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid && tokenid==tmptokenid) { PegsDecodeAccountTx(tx,pk,amount,account); @@ -581,7 +581,7 @@ double PegsGetGlobalRatio(uint256 pegstxid) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if (vout == 0 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + if (vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && (funcid=DecodePegsOpRet(tx,tmppegstxid,tokenid))!=0 && pegstxid==tmppegstxid && (funcid=='F' || funcid=='G' || funcid=='E')) { PegsDecodeAccountTx(tx,pk,amount,account); @@ -597,7 +597,7 @@ double PegsGetGlobalRatio(uint256 pegstxid) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if (GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && DecodePegsOpRet(tx,tmppegstxid,tokenid)!=0 && pegstxid==tmppegstxid) + if (myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && DecodePegsOpRet(tx,tmppegstxid,tokenid)!=0 && pegstxid==tmppegstxid) { globalaccounts[tokenid].first+=nValue; } @@ -660,7 +660,7 @@ std::string PegsCreate(uint64_t txfee,int64_t amount, std::vector bindt pegspk = GetUnspendable(cp,0); for(auto txid : bindtxids) { - if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(txid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -697,7 +697,7 @@ std::string PegsFund(uint64_t txfee,uint256 pegstxid, uint256 tokenid,int64_t am mypk = pubkey2pk(Mypubkey()); pegspk = GetUnspendable(cp,0); - if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (,yGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -711,7 +711,7 @@ std::string PegsFund(uint64_t txfee,uint256 pegstxid, uint256 tokenid,int64_t am } for(auto txid : bindtxids) { - if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(txid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -794,7 +794,7 @@ std::string PegsGet(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t am txfee = 10000; mypk = pubkey2pk(Mypubkey()); pegspk = GetUnspendable(cp,0); - if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -855,7 +855,7 @@ std::string PegsRedeem(uint64_t txfee,uint256 pegstxid, uint256 tokenid) txfee = 10000; mypk = pubkey2pk(Mypubkey()); pegspk = GetUnspendable(cp,0); - if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -869,7 +869,7 @@ std::string PegsRedeem(uint64_t txfee,uint256 pegstxid, uint256 tokenid) } for(auto txid : bindtxids) { - if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(txid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -968,7 +968,7 @@ std::string PegsExchange(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64 txfee = 10000; mypk = pubkey2pk(Mypubkey()); pegspk = GetUnspendable(cp,0); - if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -982,7 +982,7 @@ std::string PegsExchange(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64 } for(auto txid : bindtxids) { - if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(txid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1026,7 +1026,7 @@ std::string PegsExchange(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64 LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - if (accounttxid!=zeroid && GetTransaction(accounttxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0 || PegsDecodeAccountTx(tx,tmppk,tmpamount,account).empty()) + if (accounttxid!=zeroid && myGetTransaction(accounttxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0 || PegsDecodeAccountTx(tx,tmppk,tmpamount,account).empty()) { CCerror = strprintf("invalid account tx from which to exchange coins to tokens %s!",accounttxid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1104,7 +1104,7 @@ std::string PegsLiquidate(uint64_t txfee,uint256 pegstxid, uint256 tokenid, uint txfee = 10000; mypk = pubkey2pk(Mypubkey()); pegspk = GetUnspendable(cp,0); - if (GetTransaction(pegstxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1118,7 +1118,7 @@ std::string PegsLiquidate(uint64_t txfee,uint256 pegstxid, uint256 tokenid, uint } for(auto txid : bindtxids) { - if (GetTransaction(txid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(txid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find bindtxid %s",txid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1160,7 +1160,7 @@ std::string PegsLiquidate(uint64_t txfee,uint256 pegstxid, uint256 tokenid, uint LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); return(""); } - if (liquidatetxid!=zeroid && GetTransaction(liquidatetxid,tx,hashBlock,false)==0 || (numvouts=tx.vout.size())<=0 || PegsDecodeAccountTx(tx,tmppk,amount,account).empty()) + if (liquidatetxid!=zeroid && myGetTransaction(liquidatetxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0 || PegsDecodeAccountTx(tx,tmppk,amount,account).empty()) { CCerror = strprintf("cannot find account to liquidate or invalid tx %s!",liquidatetxid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); @@ -1235,7 +1235,7 @@ UniValue PegsAccountHistory(uint256 pegstxid) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second; - if (vout == 1 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + if (vout == 1 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && (funcid=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid) { UniValue obj(UniValue::VOBJ); @@ -1272,7 +1272,7 @@ UniValue PegsAccountInfo(uint256 pegstxid) vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; //LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "txid=" << txid.GetHex() << ", vout=" << vout << ", nValue=" << nValue << std::endl); - if (vout == 1 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + if (vout == 1 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && (funcid=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid) { //LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "txid=" << txid.GetHex() << ", vout=" << vout << ", nValue=" << nValue << ", tokenid=" << tmptokenid.GetHex() << std::endl); @@ -1314,7 +1314,7 @@ UniValue PegsWorstAccounts(uint256 pegstxid) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if (vout == 0 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + if (vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && (funcid=DecodePegsOpRet(tx,tmppegstxid,tokenid))!=0 && pegstxid==tmppegstxid) { PegsDecodeAccountTx(tx,pk,amount,account); @@ -1366,7 +1366,7 @@ UniValue PegsInfo(uint256 pegstxid) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if (vout == 0 && nValue == CC_MARKER_VALUE && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && + if (vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && (funcid=DecodePegsOpRet(tx,tmppegstxid,tokenid))!=0 && pegstxid==tmppegstxid) { PegsDecodeAccountTx(tx,pk,amount,account); @@ -1382,7 +1382,7 @@ UniValue PegsInfo(uint256 pegstxid) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if (GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && DecodePegsOpRet(tx,tmppegstxid,tokenid)!=0 && pegstxid==tmppegstxid) + if (myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && DecodePegsOpRet(tx,tmppegstxid,tokenid)!=0 && pegstxid==tmppegstxid) { globalaccounts[tokenid].first+=nValue; } diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 2c0a33b20..0fcc2e512 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -590,7 +590,7 @@ int64_t AddPricesInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, ch vout = (int32_t)it->first.index; //if (vout == exclvout && txid == excltxid) // exclude vout which is added directly to vins outside this function // continue; - if (GetTransaction(txid, vintx, hashBlock, false) != 0 && vout < vintx.vout.size()) + if (myGetTransaction(txid, vintx, hashBlock) != 0 && vout < vintx.vout.size()) { vscript_t vopret; uint8_t funcId = PricesCheckOpret(vintx, vopret); @@ -2161,7 +2161,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) std::vector vec; CTransaction vintx; - if (GetTransaction(txid, vintx, hashBlock, false) != 0) + if (myGetTransaction(txid, vintx, hashBlock) != 0) { // TODO: forget old tx diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 2edd275ec..2d6399737 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -357,7 +357,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont break; if ( j != mtx.vin.size() ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) != 0 ) { @@ -409,7 +409,7 @@ int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CCcontra { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) == 'F' || funcid == 'A' || funcid == 'U' || funcid == 'L' ) { @@ -439,7 +439,7 @@ bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewa { //int height = it->first.blockHeight; txid = it->first.txhash; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { //char str[65]; fprintf(stderr,"rewards plan %s\n",uint256_str(str,txid)); if ( DecodeRewardsFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,APR,minseconds,maxseconds,mindeposit) == 'F' ) @@ -455,7 +455,7 @@ bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewa UniValue RewardsInfo(uint256 rewardsid) { UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65]; - if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) + if ( myGetTransaction(rewardsid,vintx,hashBlock) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); result.push_back(Pair("result","error")); @@ -498,7 +498,7 @@ UniValue RewardsList() for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( vintx.vout.size() > 0 && DecodeRewardsFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,sbits,APR,minseconds,maxseconds,mindeposit) != 0 ) { @@ -657,7 +657,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 CCerror = "locktxid/v0 is spent"; return(""); } - if ( GetTransaction(locktxid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + if ( myGetTransaction(locktxid,tx,hashBlock) != 0 && tx.vout.size() > 0 && tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) { scriptPubKey = tx.vout[1].scriptPubKey; mtx.vin.push_back(CTxIn(locktxid,0,CScript())); diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 61ea6c545..8017799ba 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2730,7 +2730,7 @@ UniValue sudoku_txidinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params decode_hex((uint8_t *)&txid,32,txidstr); txid = revuint256(txid); result.push_back(Pair("txid",txid.GetHex())); - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { if ( sudoku_genopreturndecode(unsolved,tx.vout[numvouts-1].scriptPubKey) == 'G' ) { @@ -2780,7 +2780,7 @@ UniValue sudoku_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) //char str[65]; fprintf(stderr,"%s check %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); if ( it->second.satoshis != txfee || vout != 0 ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { if ( (nValue= IsCClibvout(cp,tx,vout,coinaddr)) == txfee && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { @@ -2861,7 +2861,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params result.push_back(Pair("txid",txid.GetHex())); if ( CCgettxout(txid,0,1,0) < 0 ) result.push_back(Pair("error","already solved")); - else if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) + else if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { Getscriptaddress(checkaddr,tx.vout[1].scriptPubKey); if ( strcmp(checkaddr,CCaddr) != 0 ) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 8407439ff..076e89a03 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -430,7 +430,7 @@ void CheckBurnTxSource(uint256 burntxid, UniValue &info) { CTransaction burnTx; uint256 blockHash; - if (!GetTransaction(burntxid, burnTx, blockHash, true)) + if (!myGetTransaction(burntxid, burnTx, blockHash)) throw std::runtime_error("Cannot find burn transaction"); if (blockHash.IsNull()) @@ -1157,7 +1157,7 @@ UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) { UniValue item(UniValue::VOBJ); UniValue notaryarr(UniValue::VARR); std::vector NotarisationNotaries; uint256 hash; CTransaction tx; - if ( GetTransaction(n.first,tx,hash,false) ) + if ( myGetTransaction(n.first,tx,hash) ) { if ( is_STAKED(n.second.symbol) != 0 ) { From 6408632ab35316f1b68c035a4508c05c98d49d3b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 01:37:46 -1100 Subject: [PATCH 604/659] Fix --- src/cc/fsm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index dca2efd2d..58b2120cf 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -133,7 +133,7 @@ int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey // prevent dup if ( it->second.satoshis < 1000000 ) continue; - if ( myGetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( (nValue= IsFSMvout(cp,vintx,(int32_t)it->first.index)) > 0 ) { From 44835832730e37df625fed255cb89d7d6d4b2855 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 01:41:12 -1100 Subject: [PATCH 605/659] -, --- src/cc/pegs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 4c3d659ae..7c64d6cd2 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -697,7 +697,7 @@ std::string PegsFund(uint64_t txfee,uint256 pegstxid, uint256 tokenid,int64_t am mypk = pubkey2pk(Mypubkey()); pegspk = GetUnspendable(cp,0); - if (,yGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) + if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("cant find pegstxid %s",pegstxid.GetHex()); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); From 66468ce589a712afc00d3d2f6ebf4a09bf25c027 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 01:42:45 -1100 Subject: [PATCH 606/659] Test --- src/cc/pegs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 7c64d6cd2..002b591c4 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -539,7 +539,7 @@ std::string PegsGetTokenName(uint256 tokenid) { CTransaction tokentx; uint256 hashBlock; std::string name,desc; std::vector vorigpubkey; int32_t numvouts; - if (myGetTransaction(tokenid,tokentx,hashBlock,false)!=0 && (numvouts=tokentx.vout.size())>0 && DecodeTokenCreateOpRet(tokentx.vout[numvouts-1].scriptPubKey,vorigpubkey,name,desc)=='c') + if (myGetTransaction(tokenid,tokentx,hashBlock)!=0 && (numvouts=tokentx.vout.size())>0 && DecodeTokenCreateOpRet(tokentx.vout[numvouts-1].scriptPubKey,vorigpubkey,name,desc)=='c') { return (name); } From 343354a1a981560cbb584792b75d64809bf03fc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 01:47:07 -1100 Subject: [PATCH 607/659] U. --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4e2e4a9c4..ff500591f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2230,10 +2230,10 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo if ( KOMODO_NSPV != 0 ) { int64_t rewardsum = 0; int32_t i,retval,txheight = 0,vout = 0; - for (i=0; i Date: Fri, 12 Jul 2019 01:50:19 -1100 Subject: [PATCH 608/659] Use hash --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ff500591f..f4928b4d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2231,7 +2231,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo { int64_t rewardsum = 0; int32_t i,retval,txheight = 0,vout = 0; for (i=0; i Date: Fri, 12 Jul 2019 02:06:48 -1100 Subject: [PATCH 609/659] +print --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 768e34fe7..91080c3f6 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -291,7 +291,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran } else { - fprintf(stderr,"vini.%d has CC signing error address.(%s)\n",i,destaddr); + fprintf(stderr,"vini.%d has CC signing error address.(%s) %s\n",i,destaddr,EncodeHexTx(mtx).c_str()); return(""); } } From fceb07f5ad5fc72fcaae0b575a8831fbdbd7e261 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 02:40:23 -1100 Subject: [PATCH 610/659] +print --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 91080c3f6..92d5f6d58 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -245,7 +245,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran // check if this is spending from 1of2 cc tokens addr: else if (strcmp(cp->tokens1of2addr, destaddr) == 0) { - //fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr); +fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr); privkey = cp->tokens1of2priv;//myprivkey; if (othercond1of2tokens == 0) // NOTE: if additionalEvalcode2 is not set then it is dual-eval cc else three-eval cc From be264f0a6910229538392376924fe4515d9a3c12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 02:44:59 -1100 Subject: [PATCH 611/659] Test --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 92d5f6d58..22f2116f5 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -175,7 +175,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); - //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,cp->unspendableaddr2); + fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,cp->tokens1of2addr); //std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " for vin[" << i << "] satoshis=" << utxovalues[i] << std::endl; if( strcmp(destaddr, myaddr) == 0 ) { From 6b6b09c4d4e5a0e65e093f6fa539ad0610f901da Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 02:54:09 -1100 Subject: [PATCH 612/659] Autodetect missing tokens address --- src/cc/CCtokens.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 289549c36..5da6e97c8 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -870,7 +870,12 @@ std::string TokenTransfer(int64_t txfee, uint256 tokenid, vscript_t destpubkey, if (txfee == 0) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) + if ( cp->tokens1of2addr[0] == 0 ) + { + GetTokensCCaddress(cp, cp->tokens1of2addr, mypk); + fprintf(stderr,"set tokens1of2addr <- %s\n",cp->tokens1of2addr); + } + if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); // seems, mask is not used anymore From 8c77b7dddc8b48af0d837fd3f46a7aa1dd74c796 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 03:02:53 -1100 Subject: [PATCH 613/659] +print --- src/cc/CCtx.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 22f2116f5..2ec5d6283 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -175,11 +175,11 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); - fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,cp->tokens1of2addr); + fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,cp->mysingletokensaddr); //std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " for vin[" << i << "] satoshis=" << utxovalues[i] << std::endl; if( strcmp(destaddr, myaddr) == 0 ) { - //fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr); +fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr); privkey = myprivkey; cond = mycond; } @@ -187,30 +187,30 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = myprivkey; cond = mytokenscond; - //fprintf(stderr,"FinalizeCCTx() matched dual-eval TokensCC1vout my token addr.(%s)\n",mytokensaddr); +fprintf(stderr,"FinalizeCCTx() matched dual-eval TokensCC1vout my token addr.(%s)\n",mytokensaddr); } else if (strcmp(destaddr, mysingletokensaddr) == 0) // if this is TokensCC1vout { privkey = myprivkey; cond = mysingletokenscond; - //fprintf(stderr, "FinalizeCCTx() matched single-eval token CC1vout my token addr.(%s)\n", mytokensaddr); +fprintf(stderr, "FinalizeCCTx() matched single-eval token CC1vout my token addr.(%s)\n", mytokensaddr); } else if ( strcmp(destaddr,unspendable) == 0 ) { privkey = unspendablepriv; cond = othercond; - //fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable); +fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable); } else if (strcmp(destaddr, unspendabletokensaddr) == 0) { privkey = unspendablepriv; cond = othertokenscond; - //fprintf(stderr,"FinalizeCCTx() matched unspendabletokensaddr dual/three-eval CC addr.(%s)\n",unspendabletokensaddr); +fprintf(stderr,"FinalizeCCTx() matched unspendabletokensaddr dual/three-eval CC addr.(%s)\n",unspendabletokensaddr); } // check if this is the 2nd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr, cp->unspendableaddr2) == 0) { - //fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2); +fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2); privkey = cp->unspendablepriv2; if( othercond2 == 0 ) othercond2 = MakeCCcond1(cp->unspendableEvalcode2, cp->unspendablepk2); @@ -219,7 +219,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran // check if this is 3rd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr3) == 0 ) { - //fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3); +fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3); privkey = cp->unspendablepriv3; if( othercond3 == 0 ) othercond3 = MakeCCcond1(cp->unspendableEvalcode3, cp->unspendablepk3); @@ -228,7 +228,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran // check if this is spending from 1of2 cc coins addr: else if (strcmp(cp->coins1of2addr, destaddr) == 0) { - //fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr); +fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr); privkey = cp->coins1of2priv;//myprivkey; if (othercond1of2 == 0) othercond1of2 = MakeCCcond1of2(cp->evalcode, cp->coins1of2pk[0], cp->coins1of2pk[1]); @@ -236,7 +236,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran } else if ( strcmp(CC1of2CCaddr,destaddr) == 0 ) { - //fprintf(stderr,"FinalizeCCTx() matched %s CC1of2CCaddr!\n",CC1of2CCaddr); +fprintf(stderr,"FinalizeCCTx() matched %s CC1of2CCaddr!\n",CC1of2CCaddr); privkey = unspendablepriv; if (condCC2 == 0) condCC2 = MakeCCcond1of2(cp->evalcode,unspendablepk,unspendablepk); @@ -270,7 +270,8 @@ fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2 cond = othercond4; flag = 1; } - } + } //else privkey = myprivkey; + if ( flag == 0 ) { fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr); From c1243f1beafbdd2acb557ec90132c84e07e24532 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 03:05:18 -1100 Subject: [PATCH 614/659] Add error check to getscriptaddress --- src/cc/CCutils.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 2430a9b37..3501b8652 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -208,10 +208,14 @@ void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, u bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey) { CTxDestination address; txnouttype whichType; - if ( ExtractDestination(scriptPubKey,address) != 0 ) + destaddr[0] = 0; + if ( scriptPubKey.begin() != 0 ) { - strcpy(destaddr,(char *)CBitcoinAddress(address).ToString().c_str()); - return(true); + if ( ExtractDestination(scriptPubKey,address) != 0 ) + { + strcpy(destaddr,(char *)CBitcoinAddress(address).ToString().c_str()); + return(true); + } } //fprintf(stderr,"ExtractDestination failed\n"); return(false); From a599f49bc439a9363ff9382e01f0378e1464c56e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 03:05:45 -1100 Subject: [PATCH 615/659] test --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 2ec5d6283..84f876fb3 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -175,7 +175,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); - fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,cp->mysingletokensaddr); + fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,mysingletokensaddr); //std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " for vin[" << i << "] satoshis=" << utxovalues[i] << std::endl; if( strcmp(destaddr, myaddr) == 0 ) { From 5f60266446ad4c334b18dcccf3b638ca8d06d87b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 03:29:06 -1100 Subject: [PATCH 616/659] Fix tokeninfo --- src/cc/CCtokens.cpp | 6 +++--- src/cc/CCtx.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 5da6e97c8..39daede80 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -870,11 +870,11 @@ std::string TokenTransfer(int64_t txfee, uint256 tokenid, vscript_t destpubkey, if (txfee == 0) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if ( cp->tokens1of2addr[0] == 0 ) + /*if ( cp->tokens1of2addr[0] == 0 ) { GetTokensCCaddress(cp, cp->tokens1of2addr, mypk); fprintf(stderr,"set tokens1of2addr <- %s\n",cp->tokens1of2addr); - } + }*/ if (AddNormalinputs(mtx, mypk, txfee, 3) > 0) { mask = ~((1LL << mtx.vin.size()) - 1); // seems, mask is not used anymore @@ -957,7 +957,7 @@ UniValue TokenInfo(uint256 tokenid) result.push_back(Pair("error", "cant find tokenid")); return(result); } - if (hashBlock.IsNull()) { + if ( KOMODO_NSPV == 0 && hashBlock.IsNull()) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "the transaction is still in mempool")); return(result); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 84f876fb3..ab21cdc3b 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -279,12 +279,12 @@ fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2 } } uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL,utxovalues[i],consensusBranchId, &txdata); + int32_t z; + for (z=0; z<32; z++) + fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); + fprintf(stderr," sighash [%d] %.8f %x\n",i,(double)utxovalues[i]/COIN,consensusBranchId); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) { - //int32_t z; - //for (z=0; z<32; z++) - // fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); - //fprintf(stderr," sighash [%d] %.8f %x\n",i,(double)utxovalues[i]/COIN,consensusBranchId); //for (z=0; z<32; z++) // fprintf(stderr,"%02x",privkey[z]); //fprintf(stderr," signed with privkey\n"); From 134b5df43987bdc5f6868323c2d52f7f8c5c3942 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 03:40:09 -1100 Subject: [PATCH 617/659] +print --- src/cryptoconditions/src/secp256k1.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index 7cb557fb0..0c1f2db79 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -157,7 +157,11 @@ static int secp256k1Sign(CC *cond, CCVisitor visitor) { int rc = secp256k1_ecdsa_sign(ec_ctx_sign, &sig, visitor.msg, signing->sk, NULL, NULL); unlockSign(); - if (rc != 1) return 0; + if (rc != 1) + { + fprintf(stderr,"secp256k1Sign rc.%d\n",rc); + return 0; + } if (!cond->signature) cond->signature = calloc(1, SECP256K1_SIG_SIZE); secp256k1_ecdsa_signature_serialize_compact(ec_ctx_verify, cond->signature, &sig); @@ -188,16 +192,22 @@ int cc_signTreeSecp256k1Msg32(CC *cond, const unsigned char *privateKey, const u } // serialize pubkey - unsigned char *publicKey = calloc(1, SECP256K1_PK_SIZE); + //unsigned char *publicKey = calloc(1, SECP256K1_PK_SIZE); + unsigned char publicKeySECP256K1_PK_SIZE]; size_t ol = SECP256K1_PK_SIZE; secp256k1_ec_pubkey_serialize(ec_ctx_verify, publicKey, &ol, &spk, SECP256K1_EC_COMPRESSED); - + { + int32_t z; + for (z=0; z<33; z++) + fprintf(stderr,"%02x",publicKey[z]); + fprintf(stderr," pubkey\n"); + } // sign CCSecp256k1SigningData signing = {publicKey, privateKey, 0}; CCVisitor visitor = {&secp256k1Sign, msg32, 32, &signing}; cc_visit(cond, visitor); - free(publicKey); + //free(publicKey); return signing.nSigned; } From f8da75a8c4cd9d03e75403c67e22a3c889e60632 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 03:42:04 -1100 Subject: [PATCH 618/659] Test --- src/cc/CCtx.cpp | 8 ++++---- src/cryptoconditions/src/secp256k1.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index ab21cdc3b..89d918037 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -280,15 +280,15 @@ fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2 } uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL,utxovalues[i],consensusBranchId, &txdata); int32_t z; + for (z=0; z<32; z++) + fprintf(stderr,"%02x",privkey[z]); + fprintf(stderr," privkey, "); for (z=0; z<32; z++) fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); fprintf(stderr," sighash [%d] %.8f %x\n",i,(double)utxovalues[i]/COIN,consensusBranchId); if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) { - //for (z=0; z<32; z++) - // fprintf(stderr,"%02x",privkey[z]); - //fprintf(stderr," signed with privkey\n"); - mtx.vin[i].scriptSig = CCSig(cond); + mtx.vin[i].scriptSig = CCSig(cond); } else { diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index 0c1f2db79..a16115bb8 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -193,7 +193,7 @@ int cc_signTreeSecp256k1Msg32(CC *cond, const unsigned char *privateKey, const u // serialize pubkey //unsigned char *publicKey = calloc(1, SECP256K1_PK_SIZE); - unsigned char publicKeySECP256K1_PK_SIZE]; + unsigned char publicKey[SECP256K1_PK_SIZE]; size_t ol = SECP256K1_PK_SIZE; secp256k1_ec_pubkey_serialize(ec_ctx_verify, publicKey, &ol, &spk, SECP256K1_EC_COMPRESSED); { From 0e4f4ee032b5862356b5c11ddc20a12e0aeb1015 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 05:16:22 -1100 Subject: [PATCH 619/659] Tweak MAX_ERAS --- src/komodo_defs.h | 2 +- src/komodo_globals.h | 2 +- src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 1ee3ef788..52d76c88c 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -275,7 +275,7 @@ extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH,KOM extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE,ASSETCHAINS_STAKED,KOMODO_NSPV; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_LASTERA,ASSETCHAINS_CBOPRET; extern bool VERUS_MINTBLOCKS; -extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; +extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; extern const char *ASSETCHAINS_ALGORITHMS[]; extern int32_t VERUS_MIN_STAKEAGE; extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 533faf981..f647b76fd 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -74,7 +74,7 @@ uint64_t ASSETCHAINS_TIMELOCKGTE = _ASSETCHAINS_TIMELOCKOFF; uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0,ASSETCHAINS_CBOPRET=0; uint64_t ASSETCHAINS_LASTERA = 1; -uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_PEGSCCPARAMS[3]; +uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_PEGSCCPARAMS[3]; uint8_t ASSETCHAINS_CCDISABLES[256]; std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; diff --git a/src/main.cpp b/src/main.cpp index f4928b4d2..f883207e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2432,7 +2432,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW) //uint64_t komodo_moneysupply(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS]; +extern uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS+1]; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; From eb1bc0cc0ce2da863ce51917200fc9b3ed5b612a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 05:21:05 -1100 Subject: [PATCH 620/659] Test ASSETCHAINS_MAX_ERAS+1 --- src/komodo_defs.h | 2 +- src/komodo_globals.h | 2 +- src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 5074b4303..748f9ee7a 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -274,7 +274,7 @@ extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH,KOM extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE,ASSETCHAINS_STAKED; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_LASTERA,ASSETCHAINS_CBOPRET; extern bool VERUS_MINTBLOCKS; -extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; +extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; extern const char *ASSETCHAINS_ALGORITHMS[]; extern int32_t VERUS_MIN_STAKEAGE; extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 9ffa147ea..c350020b6 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -74,7 +74,7 @@ uint64_t ASSETCHAINS_TIMELOCKGTE = _ASSETCHAINS_TIMELOCKOFF; uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0,ASSETCHAINS_CBOPRET=0; uint64_t ASSETCHAINS_LASTERA = 1; -uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS]; +uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1]; uint8_t ASSETCHAINS_CCDISABLES[256]; std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; diff --git a/src/main.cpp b/src/main.cpp index a8f333aa8..34708bef7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2407,7 +2407,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW) //uint64_t komodo_moneysupply(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS]; +extern uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS+1]; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; From cc7c65173758abfe1981af38970106f1c6915db6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 05:25:22 -1100 Subject: [PATCH 621/659] Remove debug --- src/komodo_nSPV_wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index df0cb9a8d..124a9a680 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -84,8 +84,8 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards)); rewardsum += rewards; } - char coinaddr[64]; - Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); + //char coinaddr[64]; + //Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); //fprintf(stderr,"%s txid.%s vs hash.%s\n",coinaddr,txid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); if ( skipvalidation == 0 ) From 3bcfaf37a616957492459aecac013bb7e5e5fad8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 05:38:20 -1100 Subject: [PATCH 622/659] Alt myprivkey method --- src/cc/CCtx.cpp | 24 +++++++++++++----------- src/cc/CCutils.cpp | 8 ++++++-- src/komodo_nSPV_wallet.h | 2 +- src/script/sign.cpp | 5 ++++- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 89d918037..5373d3d1d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -175,11 +175,11 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { Getscriptaddress(destaddr,vintx.vout[utxovout].scriptPubKey); - fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,mysingletokensaddr); + //fprintf(stderr,"FinalizeCCTx() vin.%d is CC %.8f -> (%s) vs %s\n",i,(double)utxovalues[i]/COIN,destaddr,mysingletokensaddr); //std::cerr << "FinalizeCCtx() searching destaddr=" << destaddr << " for vin[" << i << "] satoshis=" << utxovalues[i] << std::endl; if( strcmp(destaddr, myaddr) == 0 ) { -fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr); +//fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr); privkey = myprivkey; cond = mycond; } @@ -187,30 +187,30 @@ fprintf(stderr, "FinalizeCCTx() matched cc myaddr (%s)\n", myaddr); { privkey = myprivkey; cond = mytokenscond; -fprintf(stderr,"FinalizeCCTx() matched dual-eval TokensCC1vout my token addr.(%s)\n",mytokensaddr); +//fprintf(stderr,"FinalizeCCTx() matched dual-eval TokensCC1vout my token addr.(%s)\n",mytokensaddr); } else if (strcmp(destaddr, mysingletokensaddr) == 0) // if this is TokensCC1vout { privkey = myprivkey; cond = mysingletokenscond; -fprintf(stderr, "FinalizeCCTx() matched single-eval token CC1vout my token addr.(%s)\n", mytokensaddr); +//fprintf(stderr, "FinalizeCCTx() matched single-eval token CC1vout my token addr.(%s)\n", mytokensaddr); } else if ( strcmp(destaddr,unspendable) == 0 ) { privkey = unspendablepriv; cond = othercond; -fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable); +//fprintf(stderr,"FinalizeCCTx evalcode(%d) matched unspendable CC addr.(%s)\n",cp->evalcode,unspendable); } else if (strcmp(destaddr, unspendabletokensaddr) == 0) { privkey = unspendablepriv; cond = othertokenscond; -fprintf(stderr,"FinalizeCCTx() matched unspendabletokensaddr dual/three-eval CC addr.(%s)\n",unspendabletokensaddr); +//fprintf(stderr,"FinalizeCCTx() matched unspendabletokensaddr dual/three-eval CC addr.(%s)\n",unspendabletokensaddr); } // check if this is the 2nd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr, cp->unspendableaddr2) == 0) { -fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2); +//fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2); privkey = cp->unspendablepriv2; if( othercond2 == 0 ) othercond2 = MakeCCcond1(cp->unspendableEvalcode2, cp->unspendablepk2); @@ -219,7 +219,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s unspendable2!\n",cp->unspendableaddr2) // check if this is 3rd additional evalcode + 'unspendable' cc addr: else if ( strcmp(destaddr,cp->unspendableaddr3) == 0 ) { -fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3); +//fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3); privkey = cp->unspendablepriv3; if( othercond3 == 0 ) othercond3 = MakeCCcond1(cp->unspendableEvalcode3, cp->unspendablepk3); @@ -228,7 +228,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s unspendable3!\n",cp->unspendableaddr3) // check if this is spending from 1of2 cc coins addr: else if (strcmp(cp->coins1of2addr, destaddr) == 0) { -fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr); +//fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr); privkey = cp->coins1of2priv;//myprivkey; if (othercond1of2 == 0) othercond1of2 = MakeCCcond1of2(cp->evalcode, cp->coins1of2pk[0], cp->coins1of2pk[1]); @@ -236,7 +236,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s unspendable1of2!\n",cp->coins1of2addr) } else if ( strcmp(CC1of2CCaddr,destaddr) == 0 ) { -fprintf(stderr,"FinalizeCCTx() matched %s CC1of2CCaddr!\n",CC1of2CCaddr); +//fprintf(stderr,"FinalizeCCTx() matched %s CC1of2CCaddr!\n",CC1of2CCaddr); privkey = unspendablepriv; if (condCC2 == 0) condCC2 = MakeCCcond1of2(cp->evalcode,unspendablepk,unspendablepk); @@ -245,7 +245,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s CC1of2CCaddr!\n",CC1of2CCaddr); // check if this is spending from 1of2 cc tokens addr: else if (strcmp(cp->tokens1of2addr, destaddr) == 0) { -fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr); +//fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2addr); privkey = cp->tokens1of2priv;//myprivkey; if (othercond1of2tokens == 0) // NOTE: if additionalEvalcode2 is not set then it is dual-eval cc else three-eval cc @@ -293,6 +293,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2 else { fprintf(stderr,"vini.%d has CC signing error address.(%s) %s\n",i,destaddr,EncodeHexTx(mtx).c_str()); + memset(myprivkey,0,sizeof(myprivkey)); return(""); } } @@ -320,6 +321,7 @@ fprintf(stderr,"FinalizeCCTx() matched %s cp->tokens1of2addr!\n", cp->tokens1of2 cc_free(mysingletokenscond); if ( othertokenscond != 0 ) cc_free(othertokenscond); + memset(myprivkey,0,sizeof(myprivkey)); std::string strHex = EncodeHexTx(mtx); if ( strHex.size() > 0 ) return(strHex); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 3501b8652..97a1863bc 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -442,13 +442,16 @@ std::vector Mypubkey() return(pubkey); } -extern CKey NSPV_key; bool Myprivkey(uint8_t myprivkey[]) { char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33]; if ( KOMODO_NSPV != 0 ) { - NSPV_key.SetKey32(myprivkey); + vchSecret = DecodeSecret(NSPV_wifstr); + for (i=0; i<32; i++) + fprintf(stderr,"%02x",myprivkey[i]); + fprintf(stderr," myprivkey\n"); + memset(vchSecret.begin(),0,32); return true; } if ( Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG) != 0 ) @@ -465,6 +468,7 @@ bool Myprivkey(uint8_t myprivkey[]) if ( pwalletMain->GetKey(keyID,vchSecret) != 0 ) { memcpy(myprivkey,vchSecret.begin(),32); + memset(vchSecret.begin(),0,32); if ( 0 ) { for (i=0; i<32; i++) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 124a9a680..1657fa7c9 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -85,7 +85,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int rewardsum += rewards; } //char coinaddr[64]; - //Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); + //Getscriptaddress(coinaddr,tx.vout[0].scriptPubKey); causes crash?? //fprintf(stderr,"%s txid.%s vs hash.%s\n",coinaddr,txid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); if ( skipvalidation == 0 ) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 451a63d4b..0bb746797 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -74,6 +74,8 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, return false; } vchSig = CCSigVec(cc); + if ( KOMODO_NSPV != 0 ) + memset(key.begin(),0,32); return true; } else @@ -98,7 +100,8 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } vchSig.push_back((unsigned char)nHashType); - + if ( KOMODO_NSPV != 0 ) + memset(key.begin(),0,32); return true; } From 1d42b6eee2dde3b7103e46a5645ffbeca5020e54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 05:41:56 -1100 Subject: [PATCH 623/659] Syntax --- src/cc/CCutils.cpp | 6 ++++-- src/script/sign.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 97a1863bc..23ae4d7df 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -442,6 +442,8 @@ std::vector Mypubkey() return(pubkey); } +extern char NSPV_wifstr[],NSPV_pubkeystr[]; + bool Myprivkey(uint8_t myprivkey[]) { char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33]; @@ -451,7 +453,7 @@ bool Myprivkey(uint8_t myprivkey[]) for (i=0; i<32; i++) fprintf(stderr,"%02x",myprivkey[i]); fprintf(stderr," myprivkey\n"); - memset(vchSecret.begin(),0,32); + memset((uint8_t *)vchSecret.begin(),0,32); return true; } if ( Getscriptaddress(coinaddr,CScript() << Mypubkey() << OP_CHECKSIG) != 0 ) @@ -468,7 +470,7 @@ bool Myprivkey(uint8_t myprivkey[]) if ( pwalletMain->GetKey(keyID,vchSecret) != 0 ) { memcpy(myprivkey,vchSecret.begin(),32); - memset(vchSecret.begin(),0,32); + memset((uint8_t *)vchSecret.begin(),0,32); if ( 0 ) { for (i=0; i<32; i++) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 0bb746797..678a1565a 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -75,7 +75,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, } vchSig = CCSigVec(cc); if ( KOMODO_NSPV != 0 ) - memset(key.begin(),0,32); + memset((uint8_t *)key.begin(),0,32); return true; } else @@ -101,7 +101,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, vchSig.push_back((unsigned char)nHashType); if ( KOMODO_NSPV != 0 ) - memset(key.begin(),0,32); + memset((uint8_t *)key.begin(),0,32); return true; } From c0d756c17ba67c829296a917e0118d38adcf6af8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 05:51:27 -1100 Subject: [PATCH 624/659] Test --- src/cc/CCutils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 23ae4d7df..12f376179 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -18,6 +18,7 @@ */ #include "CCinclude.h" #include "komodo_structs.h" +#include "key_io.h" #ifdef TESTMODE #define MIN_NON_NOTARIZED_CONFIRMS 2 From 39fdf6130fd22050385f929594913ca1d948412b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 06:01:08 -1100 Subject: [PATCH 625/659] Actually copy out privacy --- src/cc/CCutils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 12f376179..d7d6ad8a8 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -451,9 +451,10 @@ bool Myprivkey(uint8_t myprivkey[]) if ( KOMODO_NSPV != 0 ) { vchSecret = DecodeSecret(NSPV_wifstr); + memcpy(myprivkey,vchSecret.begin(),32); for (i=0; i<32; i++) fprintf(stderr,"%02x",myprivkey[i]); - fprintf(stderr," myprivkey\n"); + fprintf(stderr," myprivkey %s\n",NSPV_wifstr); memset((uint8_t *)vchSecret.begin(),0,32); return true; } From 8bc632b4e5aaa4885787e79a68d75aa833cf6953 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 06:09:46 -1100 Subject: [PATCH 626/659] Egret --- src/cc/CCtx.cpp | 10 +++++----- src/cc/CCutils.cpp | 6 +++--- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_wallet.h | 1 + src/main.cpp | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 5373d3d1d..1048f7e35 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -46,7 +46,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); CTransaction vintx; std::string hex; CPubKey globalpk; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[CC_MAXVINS],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; - int32_t i,flag,utxovout,n,err = 0; + int32_t i,flag,mgret,utxovout,n,err = 0; char myaddr[64], destaddr[64], unspendable[64], mytokensaddr[64], mysingletokensaddr[64], unspendabletokensaddr[64],CC1of2CCaddr[64]; uint8_t *privkey, myprivkey[32], unspendablepriv[32], /*tokensunspendablepriv[32],*/ *msg32 = 0; CC *mycond=0, *othercond=0, *othercond2=0,*othercond4=0, *othercond3=0, *othercond1of2=NULL, *othercond1of2tokens = NULL, *cond=0, *condCC2=0,*mytokenscond = NULL, *mysingletokenscond = NULL, *othertokenscond = NULL; @@ -118,7 +118,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran for (i=0; i proof; + fprintf(stderr,"NSPV_gettx %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); if ( (ptr= NSPV_txproof_find(txid)) == 0 ) { NSPV_txproof(vout,txid,height); diff --git a/src/main.cpp b/src/main.cpp index f883207e5..64459e6ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2236,7 +2236,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo txheight = NSPV_U.U.utxos[i].height; break; } - retval = NSPV_gettransaction(1,vout,hash,txheight,txOut,0,0,rewardsum); + retval = NSPV_gettransaction(txheight == 0,vout,hash,txheight,txOut,0,0,rewardsum); return(retval == 0); } // need a GetTransaction without lock so the validation code for assets can run without deadlock From 2def2d9b692f21baa79e02f6efd5d14a4a763428 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 06:15:36 -1100 Subject: [PATCH 627/659] Relax mygettx --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 64459e6ba..4dba65c1a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2237,7 +2237,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo break; } retval = NSPV_gettransaction(txheight == 0,vout,hash,txheight,txOut,0,0,rewardsum); - return(retval == 0); + return(retval != -1); } // need a GetTransaction without lock so the validation code for assets can run without deadlock { From a5b391fb8907f0a98559ea554a1c0b8209389eee Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 06:16:01 -1100 Subject: [PATCH 628/659] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 4dba65c1a..6f84e5a39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2236,7 +2236,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo txheight = NSPV_U.U.utxos[i].height; break; } - retval = NSPV_gettransaction(txheight == 0,vout,hash,txheight,txOut,0,0,rewardsum); + retval = NSPV_gettransaction(1,vout,hash,txheight,txOut,0,0,rewardsum); return(retval != -1); } // need a GetTransaction without lock so the validation code for assets can run without deadlock From 61371dd0c0d036b16e95cbc1c3b029aec75e6b38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 06:24:59 -1100 Subject: [PATCH 629/659] Test --- src/cc/CCtx.cpp | 9 +++++++-- src/script/script.cpp | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 1048f7e35..5799f0b18 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -99,12 +99,17 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { if (i==0 && mtx.vin[i].prevout.n==10e8) continue; - if ( myGetTransaction(mtx.vin[i].prevout.hash,vintx,hashBlock) != 0 ) + if ( myGetTransaction(mtx.vin[i].prevout.hash,vintx,hashBlock) != 0 && mtx.vin[i].prevout.n < vintx.vout.size() ) { if ( vintx.vout[mtx.vin[i].prevout.n].scriptPubKey.IsPayToCryptoCondition() == 0 && ccvins==0) normalvins++; else ccvins++; - } + } + else + { + fprintf(stderr,"vin.%d vout.%d is bigger than vintx.%d\n",i,mtx.vin[i].prevout.n,(int32_t)vintx.vout.size()); + return(""); + } } if (normalvins>1 && ccvins) { diff --git a/src/script/script.cpp b/src/script/script.cpp index 475acdfd5..c821cd3bc 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -385,7 +385,9 @@ bool CScript::IsPayToCryptoCondition(CScript *pCCSubScript, std::vector> vParams; - return IsPayToCryptoCondition(pCCSubScript, vParams); + if ( pCCSubScript != 0 ) + return IsPayToCryptoCondition(pCCSubScript, vParams); + else return(false); } bool CScript::IsPayToCryptoCondition() const From 6024c775ac435c194e86c17c9d4d23e55f83f4b3 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 11 Jul 2019 11:42:52 -0700 Subject: [PATCH 630/659] Initial port of Hush supply curve to KMD --- src/komodo_bitcoind.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 48962b015..9882ef33c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1266,6 +1266,37 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) nSubsidy = GetBlockSubsidy(height,Params().GetConsensus()); //fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); commission = ((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); + + if ((strncmp(ASSETCHAINS_SYMBOL, "HUSH3",5) != 0)) { + int32_t starting_commission = 125000000, HALVING1 = 340000, INTERVAL = 840000, TRANSITION = 129, BR_END = 5422111; + // HUSH supply curve cannot be exactly represented via KMD AC CLI args, so we do it ourselves. + // You specify the BR, and the FR % gets added so 10% of 12.5 is 1.25 + // but to tell the AC params, I need to say "11% of 11.25" is 1.25 + // 11% ie. 1/9th cannot be exactly represented and so the FR has tiny amounts of error unless done manually + // Transition period of 128 blocks has BR=FR=0 + if (height < TRANSITION) { + commission = 0; + } else if (height < HALVING1) { + commission = starting_commission; + } else if (height < HALVING1+1*INTERVAL) { + commission = starting_commission / 2; + } else if (height < HALVING1+2*INTERVAL) { + commission = starting_commission / 4; + } else if (height < HALVING1+3*INTERVAL) { + commission = starting_commission / 8; + } else if (height < HALVING1+4*INTERVAL) { + commission = starting_commission / 16; + } else if (height < HALVING1+5*INTERVAL) { + commission = starting_commission / 32; + } else if (height < HALVING1+6*INTERVAL) { // Block 5380000 + // Block reward will go to zero between 7th+8th halvings, ac_end may need adjusting + commission = starting_commission / 64; + } else if (height < HALVING1+7*INTERVAL) { + // Block reward will be zero before this is ever reached + commission = starting_commission / 128; // Block 6220000 + } + } + if ( ASSETCHAINS_FOUNDERS > 1 ) { if ( (height % ASSETCHAINS_FOUNDERS) == 0 ) From 7d8928c5e9234af6102d291faf1a4b3c62574f4d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 12 Jul 2019 05:43:49 -0400 Subject: [PATCH 631/659] Use strncmp correctly --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9882ef33c..312e2eda1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,7 +1267,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) //fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); commission = ((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); - if ((strncmp(ASSETCHAINS_SYMBOL, "HUSH3",5) != 0)) { + if ((strncmp(ASSETCHAINS_SYMBOL, "HUSH3",5) == 0)) { int32_t starting_commission = 125000000, HALVING1 = 340000, INTERVAL = 840000, TRANSITION = 129, BR_END = 5422111; // HUSH supply curve cannot be exactly represented via KMD AC CLI args, so we do it ourselves. // You specify the BR, and the FR % gets added so 10% of 12.5 is 1.25 From 38064092949b722a0629653973a5576809335bee Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 12 Jul 2019 11:37:01 -0400 Subject: [PATCH 632/659] Optimize check for HUSH3 in komodo_commission --- src/komodo_bitcoind.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 312e2eda1..20e0f3b90 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1256,10 +1256,16 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams); uint64_t komodo_commission(const CBlock *pblock,int32_t height) { + static bool didinit = false,ishush3 = false; // LABS fungible chains, cannot have any block reward! if ( is_STAKED(ASSETCHAINS_SYMBOL) == 2 ) return(0); + if (!didinit) { + ishush3 = strncmp(ASSETCHAINS_SYMBOL, "HUSH3",5) == 0 ? true : false; + didinit = true; + } + int32_t i,j,n=0,txn_count; int64_t nSubsidy; uint64_t commission,total = 0; if ( ASSETCHAINS_FOUNDERS != 0 ) { @@ -1267,7 +1273,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) //fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); commission = ((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); - if ((strncmp(ASSETCHAINS_SYMBOL, "HUSH3",5) == 0)) { + if (ishush3) { int32_t starting_commission = 125000000, HALVING1 = 340000, INTERVAL = 840000, TRANSITION = 129, BR_END = 5422111; // HUSH supply curve cannot be exactly represented via KMD AC CLI args, so we do it ourselves. // You specify the BR, and the FR % gets added so 10% of 12.5 is 1.25 From f0398720dd51b271286226d5f73b59b81a321870 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 12 Jul 2019 10:28:01 -0700 Subject: [PATCH 633/659] Add hush convenience scripts --- src/hush-cli | 11 +++++++++++ src/hushd | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100755 src/hush-cli create mode 100755 src/hushd diff --git a/src/hush-cli b/src/hush-cli new file mode 100755 index 000000000..efa1840a6 --- /dev/null +++ b/src/hush-cli @@ -0,0 +1,11 @@ +#!/bin/bash +# Copyright (c) 2019 Hush developers + +# set working directory to the location of this script +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $DIR + +NAME=HUSH3 + +CLI=${KOMODOCLI:-./komodo-cli} +$CLI -ac_name=$NAME "$@" diff --git a/src/hushd b/src/hushd new file mode 100755 index 000000000..949779a90 --- /dev/null +++ b/src/hushd @@ -0,0 +1,52 @@ +#!/bin/bash +# Copyright (c) 2019 Hush developers + +# set working directory to the location of this script +DIR="$( cd "$( dirname "$( readlink -f "${BASH_SOURCE[0]}" )" )" && pwd )" +cd $DIR + +NAME=HUSH3 +# this corresponds to FR address RHushEyeDm7XwtaTWtyCbjGQumYyV8vMjn +SCRIPT=76a9145eb10cf64f2bab1b457f1f25e658526155928fac88ac + +# Chain parameters +ERAS=3 +BLOCKTIME=150 +# 6250000 - (sprout pool at block 500,000) +SUPPLY=6178674 +FOUNDERS=1 +REWARD=0,1125000000,562500000 +PERC=11111111 +HALVING=129,340000,840000 +# NOTE: keep in sync with komodo_bitcoind.h +END=128,340000,5422111 +CLIENTNAME=GoldenSandtrout +SEEDNODE1=188.165.212.101 +SEEDNODE2=136.243.227.142 +SEEDNODE3=5.9.224.250 +CCLIB=hush3 + +# CryptoConditions/Custom Consensus params +FAUCET=228 +HEIR=234 +CHANNEL=235 +ORACLE=236 +GATEWAY=241 +CCENABLE=$FAUCET,$HEIR,$CHANNEL,$ORACLE,$GATEWAY + +KMD=${KOMODOD:-./komodod} +$KMD -ac_name=$NAME -ac_sapling=1 \ + -ac_reward=$REWARD \ + -ac_halving=$HALVING \ + -ac_end=$END \ + -ac_eras=$ERAS \ + -ac_blocktime=$BLOCKTIME \ + -ac_cc=2 -ac_ccenable=$CCENABLE \ + -ac_founders=$FOUNDERS -ac_supply=$SUPPLY \ + -ac_perc=$PERC \ + -clientname=$CLIENTNAME \ + -addnode=$SEEDNODE1 \ + -addnode=$SEEDNODE2 \ + -addnode=$SEEDNODE3 \ + -ac_cclib=$CCLIB \ + -ac_script=$SCRIPT "$@" From 9b474d444756e2a84b958b3f4b0f29b9e9b0c320 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 12 Jul 2019 10:38:27 -0700 Subject: [PATCH 634/659] Add HUSH3 to assetchains.(old|json) --- src/assetchains.json | 22 ++++++++++++++++++++++ src/assetchains.old | 1 + 2 files changed, 23 insertions(+) diff --git a/src/assetchains.json b/src/assetchains.json index 86dc77565..910f19dd3 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -268,5 +268,27 @@ "ac_supply": "64000777", "ac_staked": "10", "addnode": ["18.197.20.21"] + }, + { + "ac_name": "HUSH3", + "ac_founders": "1", + "ac_reward": "0,1125000000,562500000" + "ac_end": "128,340000,5422111", + "ac_blocktime": "150", + "ac_supply": "6178674", + "ac_halving": "129,340000,840000", + "ac_cc": "2", + "ac_cclib": "hush3", + "ac_ccenable": "228,234,235,236,241", + "ac_supply": "100000000", + "ac_eras": "3", + "ac_script": "76a9145eb10cf64f2bab1b457f1f25e658526155928fac88ac", + "ac_sapling": "1", + "clientname": "GoldenSandtrout", + "addnode": [ + "188.165.212.101", + "136.243.227.142", + "5.9.224.250" + ] } ] diff --git a/src/assetchains.old b/src/assetchains.old index 1784bf2e1..8ee0b7daa 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -52,3 +52,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 & ./komodod -pubkey=$pubkey -ac_name=ZEXO -ac_supply=100000000 -ac_reward=1478310502 -ac_halving=525600 -ac_cc=42 -ac_ccenable=236 -ac_perc=77700 -ac_staked=93 -ac_pubkey=02713bd85e054db923694b6b7a85306264edf4d6bd6d331814f2b40af444b3ebbc -ac_public=1 -addnode=80.240.17.222 & ./komodod -pubkey=$pubkey -ac_name=K64 -ac_supply=64000777 -ac_reward=0 -ac_staked=10 -addnode=18.197.20.211 & +./komodod -pubkey=$pubkey -ac_name=HUSH3 -ac_sapling=1 -ac_reward=0,1125000000,562500000 -ac_halving=129,340000,840000 -ac_end=128,340000,5422111 -ac_eras=3 -ac_blocktime=150 -ac_cc=2 -ac_ccenable=228,234,235,236,241 -ac_founders=1 -ac_supply=6178674 -ac_perc=11111111 -clientname=GoldenSandtrout -addnode=188.165.212.101 -addnode=136.243.227.142 -addnode=5.9.224.250 -ac_cclib=hush3 -ac_script=76a9145eb10cf64f2bab1b457f1f25e658526155928fac88ac & From 8f5cbc8af21d0e1b8c04ad8405088d3fa8953ff5 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 12 Jul 2019 10:55:31 -0700 Subject: [PATCH 635/659] Missing comma --- src/assetchains.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.json b/src/assetchains.json index 910f19dd3..0b4b1644e 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -272,7 +272,7 @@ { "ac_name": "HUSH3", "ac_founders": "1", - "ac_reward": "0,1125000000,562500000" + "ac_reward": "0,1125000000,562500000", "ac_end": "128,340000,5422111", "ac_blocktime": "150", "ac_supply": "6178674", From 7d5af489141d79879710d65715137bdefe4f6eca Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 12 Jul 2019 10:59:36 -0700 Subject: [PATCH 636/659] Remove duplicate ac_supply and add ac_perc --- src/assetchains.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/assetchains.json b/src/assetchains.json index 0b4b1644e..20dd04ee2 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -271,6 +271,7 @@ }, { "ac_name": "HUSH3", + "ac_sapling": "1", "ac_founders": "1", "ac_reward": "0,1125000000,562500000", "ac_end": "128,340000,5422111", @@ -280,10 +281,9 @@ "ac_cc": "2", "ac_cclib": "hush3", "ac_ccenable": "228,234,235,236,241", - "ac_supply": "100000000", + "ac_perc": "11111111", "ac_eras": "3", "ac_script": "76a9145eb10cf64f2bab1b457f1f25e658526155928fac88ac", - "ac_sapling": "1", "clientname": "GoldenSandtrout", "addnode": [ "188.165.212.101", From d9617c68fd51617d3cb005d94f6b2ea49c8fbdd9 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 12 Jul 2019 11:05:56 -0700 Subject: [PATCH 637/659] Add fiat script --- src/fiat/hush | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 src/fiat/hush diff --git a/src/fiat/hush b/src/fiat/hush new file mode 100755 index 000000000..3d7a3425d --- /dev/null +++ b/src/fiat/hush @@ -0,0 +1,7 @@ +#!/bin/bash + +#set working directory to the location of this script +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $DIR + +../komodo-cli -ac_name=HUSH3 "$@" From 152c86ce849b349b3e905a4e4e1832c80ca7a66f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 16:39:33 -1100 Subject: [PATCH 638/659] Fix MAXERAS crash (split array overflow) --- src/komodo_defs.h | 2 +- src/komodo_globals.h | 2 +- src/komodo_utils.h | 16 ++++++++-------- src/main.cpp | 2 +- src/util.cpp | 4 ++-- src/util.h | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 748f9ee7a..5074b4303 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -274,7 +274,7 @@ extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH,ASSETCHAINS_EQUIHASH,KOM extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,KOMODO_ON_DEMAND,KOMODO_PASSPORT_INITDONE,ASSETCHAINS_STAKED; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_LASTERA,ASSETCHAINS_CBOPRET; extern bool VERUS_MINTBLOCKS; -extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; +extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; extern const char *ASSETCHAINS_ALGORITHMS[]; extern int32_t VERUS_MIN_STAKEAGE; extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index c350020b6..9ffa147ea 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -74,7 +74,7 @@ uint64_t ASSETCHAINS_TIMELOCKGTE = _ASSETCHAINS_TIMELOCKOFF; uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0,ASSETCHAINS_CBOPRET=0; uint64_t ASSETCHAINS_LASTERA = 1; -uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1]; +uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS]; uint8_t ASSETCHAINS_CCDISABLES[256]; std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 57d652309..ab58326af 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1758,10 +1758,10 @@ void komodo_args(char *argv0) ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); KOMODO_SNAPSHOT_INTERVAL = GetArg("-ac_snapshot",0); - Split(GetArg("-ac_nk",""), ASSETCHAINS_NK, 0); + Split(GetArg("-ac_nk",""), sizeof(ASSETCHAINS_NK)/sizeof(*ASSETCHAINS_NK), ASSETCHAINS_NK, 0); // -ac_ccactivateht=evalcode,height,evalcode,height,evalcode,height.... - Split(GetArg("-ac_ccactivateht",""), ccEnablesHeight, 0); + Split(GetArg("-ac_ccactivateht",""), sizeof(ccEnablesHeight)/sizeof(*ccEnablesHeight), ccEnablesHeight, 0); // fill map with all eval codes and activation height of 0. for ( int i = 0; i < 256; i++ ) mapHeightEvalActivate[i] = 0; @@ -1833,11 +1833,11 @@ void komodo_args(char *argv0) ASSETCHAINS_TIMEUNLOCKFROM = ASSETCHAINS_TIMEUNLOCKTO = 0; } - Split(GetArg("-ac_end",""), ASSETCHAINS_ENDSUBSIDY, 0); - Split(GetArg("-ac_reward",""), ASSETCHAINS_REWARD, 0); - Split(GetArg("-ac_halving",""), ASSETCHAINS_HALVING, 0); - Split(GetArg("-ac_decay",""), ASSETCHAINS_DECAY, 0); - Split(GetArg("-ac_notarypay",""), ASSETCHAINS_NOTARY_PAY, 0); + Split(GetArg("-ac_end",""), sizeof(ASSETCHAINS_ENDSUBSIDY)/sizeof(*ASSETCHAINS_ENDSUBSIDY), ASSETCHAINS_ENDSUBSIDY, 0); + Split(GetArg("-ac_reward",""), sizeof(ASSETCHAINS_REWARD)/sizeof(*ASSETCHAINS_REWARD), ASSETCHAINS_REWARD, 0); + Split(GetArg("-ac_halving",""), sizeof(ASSETCHAINS_HALVING)/sizeof(*ASSETCHAINS_HALVING), ASSETCHAINS_HALVING, 0); + Split(GetArg("-ac_decay",""), sizeof(ASSETCHAINS_DECAY)/sizeof(*ASSETCHAINS_DECAY), ASSETCHAINS_DECAY, 0); + Split(GetArg("-ac_notarypay",""), sizeof(ASSETCHAINS_NOTARY_PAY)/sizeof(*ASSETCHAINS_NOTARY_PAY), ASSETCHAINS_NOTARY_PAY, 0); for ( int i = 0; i < ASSETCHAINS_MAX_ERAS; i++ ) { @@ -1906,7 +1906,7 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_CC != 0 ) { ASSETCHAINS_CCLIB = GetArg("-ac_cclib",""); - Split(GetArg("-ac_ccenable",""), ccenables, 0); + Split(GetArg("-ac_ccenable",""), sizeof(ccenables)/sizeof(*ccenables), ccenables, 0); for (i=nonz=0; i<0x100; i++) { if ( ccenables[i] != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 34708bef7..a8f333aa8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2407,7 +2407,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW) //uint64_t komodo_moneysupply(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS+1]; +extern uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS]; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; diff --git a/src/util.cpp b/src/util.cpp index 1aa079085..9daecb63e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -414,7 +414,7 @@ void SplitStr(const std::string& strVal, std::vector &outVals) } } -void Split(const std::string& strVal, uint64_t *outVals, const uint64_t nDefault) +void Split(const std::string& strVal, int32_t outsize, uint64_t *outVals, const uint64_t nDefault) { stringstream ss(strVal); vector vec; @@ -442,7 +442,7 @@ void Split(const std::string& strVal, uint64_t *outVals, const uint64_t nDefault else nLast = nDefault; - for ( i = numVals; i < ASSETCHAINS_MAX_ERAS; i++ ) + for ( i = numVals; i < outsize; i++ ) { outVals[i] = nLast; } diff --git a/src/util.h b/src/util.h index 617faaf36..17bf19952 100644 --- a/src/util.h +++ b/src/util.h @@ -185,7 +185,7 @@ inline bool IsSwitchChar(char c) * else if the string has fewer than _MAX_ERAS entries, then the last * entry fills remaining entries */ -void Split(const std::string& strVal, uint64_t *outVals, uint64_t nDefault); +void Split(const std::string& strVal, int32_t outsize, uint64_t *outVals, uint64_t nDefault); /** * Return string argument or default value From 043199aa4a955a8896dc45f721b0aa398e7ff511 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 16:42:15 -1100 Subject: [PATCH 639/659] Merge --- src/komodo_globals.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index cd1ed5b6a..53e304a9b 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -46,11 +46,8 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; uint256 KOMODO_EARLYTXID; -<<<<<<< HEAD + int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,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,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY,KOMODO_NSPV; -======= -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,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,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS,ASSETCHAINS_CBMATURITY; ->>>>>>> dev int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; From 5af5292f52105531ee9d44513b8c219c7d4ba5a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 16:50:50 -1100 Subject: [PATCH 640/659] sizeof(ASSETCHAINS_PEGSCCPARAMS)/sizeof(*ASSETCHAINS_PEGSCCPARAMS) --- src/komodo_nSPV.h | 1 + src/komodo_utils.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 069ddb4ab..d7c6ebfc8 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -17,6 +17,7 @@ // todo: // myprivkey, scrub all destination buffers +// oversized tx // headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs diff --git a/src/komodo_utils.h b/src/komodo_utils.h index fbbe4c677..5d6f2722b 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1973,7 +1973,7 @@ void komodo_args(char *argv0) } else if ( ASSETCHAINS_SELFIMPORT == "PEGSCC") { - Split(GetArg("-ac_pegsccparams",""), ASSETCHAINS_PEGSCCPARAMS, 0); + Split(GetArg("-ac_pegsccparams",""), sizeof(ASSETCHAINS_PEGSCCPARAMS)/sizeof(*ASSETCHAINS_PEGSCCPARAMS), ASSETCHAINS_PEGSCCPARAMS, 0); if (ASSETCHAINS_ENDSUBSIDY[0]!=1 || ASSETCHAINS_COMMISSION!=0) { fprintf(stderr,"when using import for pegsCC these must be set: -ac_end=1 -ac_perc=0\n"); From e4c67ed018e99702aeac1833aa225281b7716a4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 16:57:51 -1100 Subject: [PATCH 641/659] sizeof(ASSETCHAINS_PEGSCCPARAMS)/sizeof(*ASSETCHAINS_PEGSCCPARAMS) --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index fbbe4c677..5d6f2722b 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1973,7 +1973,7 @@ void komodo_args(char *argv0) } else if ( ASSETCHAINS_SELFIMPORT == "PEGSCC") { - Split(GetArg("-ac_pegsccparams",""), ASSETCHAINS_PEGSCCPARAMS, 0); + Split(GetArg("-ac_pegsccparams",""), sizeof(ASSETCHAINS_PEGSCCPARAMS)/sizeof(*ASSETCHAINS_PEGSCCPARAMS), ASSETCHAINS_PEGSCCPARAMS, 0); if (ASSETCHAINS_ENDSUBSIDY[0]!=1 || ASSETCHAINS_COMMISSION!=0) { fprintf(stderr,"when using import for pegsCC these must be set: -ac_end=1 -ac_perc=0\n"); From 92a8d1f89e4fd4d3dc831bf45aaf135291eae5fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 18:04:41 -1100 Subject: [PATCH 642/659] +print --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f3b714eaa..47a39129c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8062,6 +8062,7 @@ bool ProcessMessages(CNode* pfrom) // (x) data // bool fOk = true; +fprintf(stderr,"process messages\n"); if (!pfrom->vRecvGetData.empty()) ProcessGetData(pfrom); @@ -8175,7 +8176,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Don't send anything until we get its version message if (pto->nVersion == 0) return true; - +fprintf(stderr,"send messages\n"); // // Message: ping // From 96daa77e34f044482125775b713c2b62b1b8df23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 18:12:23 -1100 Subject: [PATCH 643/659] -orint --- src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 47a39129c..f3b714eaa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8062,7 +8062,6 @@ bool ProcessMessages(CNode* pfrom) // (x) data // bool fOk = true; -fprintf(stderr,"process messages\n"); if (!pfrom->vRecvGetData.empty()) ProcessGetData(pfrom); @@ -8176,7 +8175,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Don't send anything until we get its version message if (pto->nVersion == 0) return true; -fprintf(stderr,"send messages\n"); + // // Message: ping // From 506cf51b629036492f423a85634e8dd4e152574e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 18:18:10 -1100 Subject: [PATCH 644/659] -lock --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 3215abab3..d8a1b8f1e 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -207,7 +207,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind) if ( pnode == 0 ) { memset(pnodes,0,sizeof(pnodes)); - LOCK(cs_vNodes); + //LOCK(cs_vNodes); n = 0; BOOST_FOREACH(CNode *ptr,vNodes) { From 4701a9c2f6699dc36d2bfb6960687562ecf28308 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 18:22:29 -1100 Subject: [PATCH 645/659] Longer poll --- src/komodo_nSPV_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index c72fb2aeb..efbe7d7ae 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -17,7 +17,7 @@ #ifndef KOMODO_NSPV_DEFSH #define KOMODO_NSPV_DEFSH -#define NSPV_POLLITERS 15 +#define NSPV_POLLITERS 50 #define NSPV_POLLMICROS 100000 #define NSPV_MAXVINS 64 #define NSPV_AUTOLOGOUT 777 From eafa3f703da26769aa19515bceb4ff3d2cdd35d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 18:38:44 -1100 Subject: [PATCH 646/659] 10 second timeout --- src/komodo_nSPV_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index efbe7d7ae..2a7a88b22 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -17,7 +17,7 @@ #ifndef KOMODO_NSPV_DEFSH #define KOMODO_NSPV_DEFSH -#define NSPV_POLLITERS 50 +#define NSPV_POLLITERS 100 #define NSPV_POLLMICROS 100000 #define NSPV_MAXVINS 64 #define NSPV_AUTOLOGOUT 777 From 223152deab0ebf0c2d0f08f48618750fc397eda8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 18:39:02 -1100 Subject: [PATCH 647/659] 5 seconds --- src/komodo_nSPV_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 2a7a88b22..588636dc2 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -18,7 +18,7 @@ #define KOMODO_NSPV_DEFSH #define NSPV_POLLITERS 100 -#define NSPV_POLLMICROS 100000 +#define NSPV_POLLMICROS 50000 #define NSPV_MAXVINS 64 #define NSPV_AUTOLOGOUT 777 #define NSPV_BRANCHID 0x76b809bb From faa44230c1d15fdbf6e9f256a41d34e529da35f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 19:38:15 -1100 Subject: [PATCH 648/659] Bigtxlen --- src/komodo_nSPV.h | 11 ++++------- src/komodo_nSPV_defs.h | 6 ++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index d7c6ebfc8..84bb67af1 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -66,11 +66,11 @@ int32_t iguana_rwequihdrvec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsize return(len); } -int32_t iguana_rwuint8vec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsizep,uint8_t **ptrp) +int32_t iguana_rwuint8vec(int32_t rwflag,uint8_t *serialized,uint32_t *biglenp,uint8_t **ptrp) { int32_t vsize,len = 0; - len += iguana_rwnum(rwflag,&serialized[len],sizeof(*vecsizep),vecsizep); - if ( (vsize= *vecsizep) != 0 ) + len += iguana_rwnum(rwflag,&serialized[len],sizeof(*biglenp),biglenp); + if ( (vsize= *biglenp) != 0 && vsize < MAX_TX_SIZE_AFTER_SAPLING ) { if ( *ptrp == 0 ) *ptrp = (uint8_t *)calloc(1,vsize); // relies on uint16_t being "small" to prevent mem exhaustion @@ -195,7 +195,6 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->unspentvalue),&ptr->unspentvalue); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad),&ptr->pad); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); return(len); @@ -204,7 +203,7 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p void NSPV_txproof_copy(struct NSPV_txproof *dest,struct NSPV_txproof *ptr) { *dest = *ptr; - if ( ptr->tx != 0 ) + if ( ptr->tx != 0 && ptr->txlen < MAX_TX_SIZE_AFTER_SAPLING ) { dest->tx = (uint8_t *)malloc(ptr->txlen); memcpy(dest->tx,ptr->tx,ptr->txlen); @@ -234,7 +233,6 @@ int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz len += iguana_rwequihdrvec(rwflag,&serialized[len],&ptr->numhdrs,&ptr->hdrs); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevht),&ptr->prevht); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nextht),&ptr->nextht); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); //fprintf(stderr,"rwcommon prev.%d next.%d\n",ptr->prevht,ptr->nextht); return(len); @@ -246,7 +244,6 @@ int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzs len += NSPV_rwntzproofshared(rwflag,&serialized[len],&ptr->common); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->prevtxid),(uint8_t *)&ptr->prevtxid); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->nexttxid),(uint8_t *)&ptr->nexttxid); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevtxidht),&ptr->prevtxidht); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nexttxidht),&ptr->nexttxidht); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->prevtxlen,&ptr->prevntz); diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 588636dc2..31c53fa22 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -97,8 +97,7 @@ struct NSPV_txproof { uint256 txid; int64_t unspentvalue; - int32_t height,vout,pad; - uint16_t txlen,txprooflen; + int32_t height,vout,txlen,txprooflen; uint8_t *tx,*txproof; }; @@ -113,8 +112,7 @@ struct NSPV_ntzsproofresp { struct NSPV_ntzproofshared common; uint256 prevtxid,nexttxid; - int32_t pad32,prevtxidht,nexttxidht; - uint16_t prevtxlen,nexttxlen; + int32_t prevtxidht,nexttxidht,prevtxlen,nexttxlen; uint8_t *prevntz,*nextntz; }; From e43eb755e7ffa2c68e2673291a8542ea6c26f2c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 19:43:37 -1100 Subject: [PATCH 649/659] Uint --- src/komodo_nSPV.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 84bb67af1..642c6ed8d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -66,11 +66,11 @@ int32_t iguana_rwequihdrvec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsize return(len); } -int32_t iguana_rwuint8vec(int32_t rwflag,uint8_t *serialized,uint32_t *biglenp,uint8_t **ptrp) +int32_t iguana_rwuint8vec(int32_t rwflag,uint8_t *serialized,int32_t *biglenp,uint8_t **ptrp) { int32_t vsize,len = 0; len += iguana_rwnum(rwflag,&serialized[len],sizeof(*biglenp),biglenp); - if ( (vsize= *biglenp) != 0 && vsize < MAX_TX_SIZE_AFTER_SAPLING ) + if ( (vsize= *biglenp) > 0 && vsize < MAX_TX_SIZE_AFTER_SAPLING ) { if ( *ptrp == 0 ) *ptrp = (uint8_t *)calloc(1,vsize); // relies on uint16_t being "small" to prevent mem exhaustion From 978d16a32b03d4222b73136b0289f1ed84b69834 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 19:45:04 -1100 Subject: [PATCH 650/659] int32_t --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index da15c82e1..6300a77dd 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -185,7 +185,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC return(0); } -uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,uint16_t *txlenp,uint256 txid) +uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,int32_t *txlenp,uint256 txid) { uint8_t *rawtx = 0; *txlenp = 0; From c7d0054214619f95958a28878f887c2f850367f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 20:42:45 -1100 Subject: [PATCH 651/659] int16 -> int32 --- src/komodo_nSPV.h | 4 ++-- src/komodo_nSPV_fullnode.h | 7 +++---- src/komodo_nSPV_superlite.h | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 642c6ed8d..6500b9688 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -29,7 +29,7 @@ #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H -int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf) +int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *buf) { if ( rwflag != 0 ) memcpy(serialized,buf,len); @@ -73,7 +73,7 @@ int32_t iguana_rwuint8vec(int32_t rwflag,uint8_t *serialized,int32_t *biglenp,ui if ( (vsize= *biglenp) > 0 && vsize < MAX_TX_SIZE_AFTER_SAPLING ) { if ( *ptrp == 0 ) - *ptrp = (uint8_t *)calloc(1,vsize); // relies on uint16_t being "small" to prevent mem exhaustion + *ptrp = (uint8_t *)calloc(1,vsize); len += iguana_rwbuf(rwflag,&serialized[len],vsize,*ptrp); } return(len); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 6300a77dd..2479d0cdc 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -190,7 +190,6 @@ uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,int32_t *txlenp,uint2 uint8_t *rawtx = 0; *txlenp = 0; { - LOCK(cs_main); if (!GetTransaction(txid, tx, hashBlock, false)) return(0); string strHex = EncodeHexTx(tx); @@ -210,7 +209,7 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int ptr->retcode = 0; if ( NSPV_txextract(tx,data,n) == 0 ) { - LOCK(cs_main); + //LOCK(cs_main); ptr->txid = tx.GetHash(); //fprintf(stderr,"try to addmempool transaction %s\n",ptr->txid.GetHex().c_str()); if ( myAddtomempool(tx) != 0 ) @@ -496,14 +495,14 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { if ( timestamp > pfrom->prevtimes[ind] ) { - struct NSPV_broadcastresp B; uint16_t n,offset; uint256 txid; + struct NSPV_broadcastresp B; uint32_t n,offset; uint256 txid; if ( len > 1+sizeof(txid)+sizeof(n) ) { iguana_rwbignum(0,&request[1],sizeof(txid),(uint8_t *)&txid); iguana_rwnum(0,&request[1+sizeof(txid)],sizeof(n),&n); memset(&B,0,sizeof(B)); offset = 1 + sizeof(txid) + sizeof(n); - if ( request.size() == offset+n && (slen= NSPV_sendrawtransaction(&B,&request[offset],n)) > 0 ) + if ( n < MAX_TX_SIZE_AFTER_SAPLING && request.size() == offset+n && (slen= NSPV_sendrawtransaction(&B,&request[offset],n)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_BROADCASTRESP; diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d8a1b8f1e..259f9cbc3 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -593,7 +593,7 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid); - //for (iter=0; iter<3; iter++); + for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i> 1; data = (uint8_t *)malloc(n); From 2487a1079bc2c9b3f3ea678f625f06ecd75acc62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 21:01:21 -1100 Subject: [PATCH 652/659] Test --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_fullnode.h | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 6500b9688..ad805848d 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -248,6 +248,7 @@ int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzs len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nexttxidht),&ptr->nexttxidht); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->prevtxlen,&ptr->prevntz); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->nexttxlen,&ptr->nextntz); + fprintf(stderr,"retlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 2479d0cdc..069b974ad 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -290,7 +290,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid fprintf(stderr,"illegal prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); return(-7); } - //fprintf(stderr,"%s -> prevht.%d, %s -> nexht.%d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); + fprintf(stderr,"%s -> prevht.%d, %s -> nexht.%d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); ptr->common.numhdrs = (ptr->common.nextht - ptr->common.prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); @@ -426,9 +426,9 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req iguana_rwbignum(0,&request[1],sizeof(prevntz),(uint8_t *)&prevntz); iguana_rwbignum(0,&request[1+sizeof(prevntz)],sizeof(nextntz),(uint8_t *)&nextntz); memset(&P,0,sizeof(P)); - //fprintf(stderr,"msg prev.%s next.%s\n",prevntz.GetHex().c_str(),nextntz.GetHex().c_str()); if ( (slen= NSPV_getntzsproofresp(&P,prevntz,nextntz)) > 0 ) { + fprintf(stderr,"slen.%d msg prev.%s next.%s\n",slen,prevntz.GetHex().c_str(),nextntz.GetHex().c_str()); response.resize(1 + slen); response[0] = NSPV_NTZSPROOFRESP; if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) @@ -437,7 +437,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req pfrom->prevtimes[ind] = timestamp; } NSPV_ntzsproofresp_purge(&P); - } + } else fprintf(stderr,"err.%d\n",slen); } } } From 7a5a52c89b8a2cd932a3542784b1e037f09e08b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 21:20:15 -1100 Subject: [PATCH 653/659] +prints --- src/komodo_nSPV_fullnode.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 069b974ad..245a9c79d 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -290,7 +290,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid fprintf(stderr,"illegal prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht); return(-7); } - fprintf(stderr,"%s -> prevht.%d, %s -> nexht.%d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); + //fprintf(stderr,"%s -> prevht.%d, %s -> nexht.%d\n",ptr->prevtxid.GetHex().c_str(),ptr->common.prevht,ptr->nexttxid.GetHex().c_str(),ptr->common.nextht); ptr->common.numhdrs = (ptr->common.nextht - ptr->common.prevht + 1); ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs)); //fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs); @@ -306,6 +306,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid return(-1); } } + fprintf(stderr,"sizeof ptr %ld, common.%ld lens.%d %d\n",sizeof(*ptr),sizeof(ptr->common),ptr->prevtxlen,ptr->nexttxlen); return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevtxlen + ptr->nexttxlen); } From 5bd1c6b9b1bb925222dafc5525ccc8b2de45808f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 21:34:27 -1100 Subject: [PATCH 654/659] Fix padding --- src/komodo_nSPV.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index ad805848d..24f4a221e 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -233,6 +233,7 @@ int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz len += iguana_rwequihdrvec(rwflag,&serialized[len],&ptr->numhdrs,&ptr->hdrs); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevht),&ptr->prevht); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nextht),&ptr->nextht); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad16),&ptr->pad16); //fprintf(stderr,"rwcommon prev.%d next.%d\n",ptr->prevht,ptr->nextht); return(len); From ef9b319f96939a4c435c7cd106a355ae9dbcae1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 21:43:15 -1100 Subject: [PATCH 655/659] Error check --- src/komodo_nSPV.h | 15 +++++++++------ src/komodo_nSPV_fullnode.h | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 24f4a221e..67bfd6bb0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -249,7 +249,7 @@ int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzs len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nexttxidht),&ptr->nexttxidht); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->prevtxlen,&ptr->prevntz); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->nexttxlen,&ptr->nextntz); - fprintf(stderr,"retlen.%d\n",len); + //fprintf(stderr,"retlen.%d\n",len); return(len); } @@ -349,11 +349,14 @@ uint256 NSPV_hdrhash(struct NSPV_equihdr *hdr) int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen) { std::vector rawdata; - rawdata.resize(datalen); - memcpy(&rawdata[0],data,datalen); - if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) - return(0); - else return(-1); + if ( datalen < MAX_TX_SIZE_AFTER_SAPLING ) + { + rawdata.resize(datalen); + memcpy(&rawdata[0],data,datalen); + if ( DecodeHexTx(tx,HexStr(rawdata)) != 0 ) + return(0); + } + return(-1); } bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 245a9c79d..9e44df3a7 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -306,7 +306,7 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid return(-1); } } - fprintf(stderr,"sizeof ptr %ld, common.%ld lens.%d %d\n",sizeof(*ptr),sizeof(ptr->common),ptr->prevtxlen,ptr->nexttxlen); + //fprintf(stderr,"sizeof ptr %ld, common.%ld lens.%d %d\n",sizeof(*ptr),sizeof(ptr->common),ptr->prevtxlen,ptr->nexttxlen); return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevtxlen + ptr->nexttxlen); } @@ -429,7 +429,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&P,0,sizeof(P)); if ( (slen= NSPV_getntzsproofresp(&P,prevntz,nextntz)) > 0 ) { - fprintf(stderr,"slen.%d msg prev.%s next.%s\n",slen,prevntz.GetHex().c_str(),nextntz.GetHex().c_str()); + // fprintf(stderr,"slen.%d msg prev.%s next.%s\n",slen,prevntz.GetHex().c_str(),nextntz.GetHex().c_str()); response.resize(1 + slen); response[0] = NSPV_NTZSPROOFRESP; if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen ) From f9b2683ceedc47a2ab970c76efb78a0cf4d64d5a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 21:45:41 -1100 Subject: [PATCH 656/659] -sleep --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 0de278539..c48358f33 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -44,7 +44,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) return(-i-13); } - sleep(1); + //sleep(1); if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) return(-8); else if ( tx.GetHash() != ptr->prevtxid ) From a3c673629407e4ad4d9afb11a56dfd80b55bf394 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 21:47:38 -1100 Subject: [PATCH 657/659] Revert --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index c48358f33..677977723 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -44,7 +44,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) if ( blockhash != ptr->common.hdrs[i].hashPrevBlock ) return(-i-13); } - //sleep(1); + sleep(1); // need this to get past the once per second rate limiter per message if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 ) return(-8); else if ( tx.GetHash() != ptr->prevtxid ) From 097f94b78ebe0768c93053ed6ac66832128e6621 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 21:55:38 -1100 Subject: [PATCH 658/659] -print --- src/komodo_nSPV_wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 677977723..d7ff5e1a7 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -61,7 +61,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr) int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum) { struct NSPV_txproof *ptr; int32_t i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; - fprintf(stderr,"NSPV_gettx %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); + //fprintf(stderr,"NSPV_gettx %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); if ( (ptr= NSPV_txproof_find(txid)) == 0 ) { NSPV_txproof(vout,txid,height); From f963001d0b69cb8feca769bad5aec4e7151d97ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Jul 2019 22:07:56 -1100 Subject: [PATCH 659/659] Reduce getinfo footprint --- src/rpc/misc.cpp | 91 +++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 95c2cc343..384b487b2 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -222,17 +222,17 @@ UniValue getinfo(const UniValue& params, bool fHelp) + HelpExampleCli("getinfo", "") + HelpExampleRpc("getinfo", "") ); -//#ifdef ENABLE_WALLET -// LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL); -//#else + //#ifdef ENABLE_WALLET + // LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL); + //#else LOCK(cs_main); -//#endif - + //#endif + proxyType proxy; GetProxy(NET_IPV4, proxy); notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); //fprintf(stderr,"after notarized_height %u\n",(uint32_t)time(NULL)); - + UniValue obj(UniValue::VOBJ); obj.push_back(Pair("version", CLIENT_VERSION)); obj.push_back(Pair("protocolversion", PROTOCOL_VERSION)); @@ -243,50 +243,54 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("prevMoMheight", prevMoMheight)); obj.push_back(Pair("notarizedhash", notarized_hash.ToString())); obj.push_back(Pair("notarizedtxid", notarized_desttxid.ToString())); - txid_height = notarizedtxid_height(ASSETCHAINS_SYMBOL[0] != 0 ? (char *)"KMD" : (char *)"BTC",(char *)notarized_desttxid.ToString().c_str(),&kmdnotarized_height); - if ( txid_height > 0 ) - obj.push_back(Pair("notarizedtxid_height", txid_height)); - else obj.push_back(Pair("notarizedtxid_height", "mempool")); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - obj.push_back(Pair("KMDnotarized_height", kmdnotarized_height)); - obj.push_back(Pair("notarized_confirms", txid_height < kmdnotarized_height ? (kmdnotarized_height - txid_height + 1) : 0)); - //fprintf(stderr,"after notarized_confirms %u\n",(uint32_t)time(NULL)); + if ( KOMODO_NSPV == 0 ) + { + txid_height = notarizedtxid_height(ASSETCHAINS_SYMBOL[0] != 0 ? (char *)"KMD" : (char *)"BTC",(char *)notarized_desttxid.ToString().c_str(),&kmdnotarized_height); + if ( txid_height > 0 ) + obj.push_back(Pair("notarizedtxid_height", txid_height)); + else obj.push_back(Pair("notarizedtxid_height", "mempool")); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + obj.push_back(Pair("KMDnotarized_height", kmdnotarized_height)); + obj.push_back(Pair("notarized_confirms", txid_height < kmdnotarized_height ? (kmdnotarized_height - txid_height + 1) : 0)); + //fprintf(stderr,"after notarized_confirms %u\n",(uint32_t)time(NULL)); #ifdef ENABLE_WALLET - if (pwalletMain) { - obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); - if ( ASSETCHAINS_SYMBOL[0] == 0 ) - { - obj.push_back(Pair("interest", ValueFromAmount(KOMODO_INTERESTSUM))); - obj.push_back(Pair("balance", ValueFromAmount(KOMODO_WALLETBALANCE))); //pwalletMain->GetBalance() + if (pwalletMain) { + obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + { + obj.push_back(Pair("interest", ValueFromAmount(KOMODO_INTERESTSUM))); + obj.push_back(Pair("balance", ValueFromAmount(KOMODO_WALLETBALANCE))); //pwalletMain->GetBalance() + } + else + { + obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); // + } } - else - { - obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); // - } - } #endif - //fprintf(stderr,"after wallet %u\n",(uint32_t)time(NULL)); - obj.push_back(Pair("blocks", (int)chainActive.Height())); - if ( (longestchain= KOMODO_LONGESTCHAIN) != 0 && chainActive.Height() > longestchain ) - longestchain = chainActive.Height(); - //fprintf(stderr,"after longestchain %u\n",(uint32_t)time(NULL)); - obj.push_back(Pair("longestchain", longestchain)); + //fprintf(stderr,"after wallet %u\n",(uint32_t)time(NULL)); + obj.push_back(Pair("blocks", (int)chainActive.Height())); + if ( (longestchain= KOMODO_LONGESTCHAIN) != 0 && chainActive.Height() > longestchain ) + longestchain = chainActive.Height(); + //fprintf(stderr,"after longestchain %u\n",(uint32_t)time(NULL)); + obj.push_back(Pair("longestchain", longestchain)); + if ( chainActive.LastTip() != 0 ) + obj.push_back(Pair("tiptime", (int)chainActive.LastTip()->nTime)); + obj.push_back(Pair("difficulty", (double)GetDifficulty())); +#ifdef ENABLE_WALLET + if (pwalletMain) { + obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime())); + obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); + } + if (pwalletMain && pwalletMain->IsCrypted()) + obj.push_back(Pair("unlocked_until", nWalletUnlockTime)); + obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()))); +#endif + obj.push_back(Pair("sapling", ASSETCHAINS_SAPLING)); + } obj.push_back(Pair("timeoffset", GetTimeOffset())); - if ( chainActive.LastTip() != 0 ) - obj.push_back(Pair("tiptime", (int)chainActive.LastTip()->nTime)); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC())); -#ifdef ENABLE_WALLET - if (pwalletMain) { - obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime())); - obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); - } - if (pwalletMain && pwalletMain->IsCrypted()) - obj.push_back(Pair("unlocked_until", nWalletUnlockTime)); - obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK()))); -#endif obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()))); obj.push_back(Pair("errors", GetWarnings("statusbar"))); if ( NOTARY_PUBKEY33[0] != 0 ) { @@ -304,7 +308,6 @@ UniValue getinfo(const UniValue& params, bool fHelp) if ( ASSETCHAINS_CC != 0 ) obj.push_back(Pair("CCid", (int)ASSETCHAINS_CC)); obj.push_back(Pair("name", ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)); - obj.push_back(Pair("sapling", ASSETCHAINS_SAPLING)); obj.push_back(Pair("p2pport", ASSETCHAINS_P2PPORT)); obj.push_back(Pair("rpcport", ASSETCHAINS_RPCPORT));