From 9b0e1808f32265c291d197bb597fb35c50e3aa34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 11:59:33 -0300 Subject: [PATCH 001/205] test --- src/komodo.h | 4 ++ src/komodo_bitcoind.h | 88 +++++++++++++++++++++++++++++++++++++++++++ src/komodo_gateway.h | 24 ++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/komodo_gateway.h diff --git a/src/komodo.h b/src/komodo.h index f7dc35ea1..37d9f6df6 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -263,6 +263,10 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count,flag; komodo_init(); +#ifdef KOMODO_ISSUER + komodo_gateway_issuer(); +#else +#endif if ( pindex != 0 ) { height = pindex->nHeight; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e566ce84a..7511d165d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -15,6 +15,94 @@ // komodo functions that interact with bitcoind C++ +#ifdef _WIN32 +#include +#include +#else +#include +#include +#endif + +struct MemoryStruct { char *memory; size_t size; }; + +static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) +{ + size_t realsize = (size * nmemb); + struct MemoryStruct *mem = (struct MemoryStruct *)data; + mem->memory = (ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1); + if ( mem->memory != 0 ) + { + if ( ptr != 0 ) + memcpy(&(mem->memory[mem->size]),ptr,realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + } + //printf("got %d bytes\n",(int32_t)(size*nmemb)); + return(realsize); +} + +void *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3) +{ + struct MemoryStruct chunk; CURL *cHandle; long code; struct curl_slist *headers = 0; + if ( (cHandle= *cHandlep) == NULL ) + *cHandlep = cHandle = curl_easy_init(); + else curl_easy_reset(cHandle); + //#ifdef DEBUG + //curl_easy_setopt(cHandle,CURLOPT_VERBOSE, 1); + //#endif + curl_easy_setopt(cHandle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + curl_easy_setopt(cHandle,CURLOPT_SSL_VERIFYPEER,0); + //curl_easy_setopt(cHandle,CURLOPT_SSLVERSION,1); + curl_easy_setopt(cHandle,CURLOPT_URL,url); + curl_easy_setopt(cHandle,CURLOPT_CONNECTTIMEOUT,10); + if ( userpass != 0 && userpass[0] != 0 ) + curl_easy_setopt(cHandle,CURLOPT_USERPWD,userpass); + if ( postfields != 0 && postfields[0] != 0 ) + { + curl_easy_setopt(cHandle,CURLOPT_POST,1); + curl_easy_setopt(cHandle,CURLOPT_POSTFIELDS,postfields); + } + if ( hdr0 != NULL && hdr0[0] != 0 ) + { + //printf("HDR0.(%s) HDR1.(%s) HDR2.(%s) HDR3.(%s)\n",hdr0!=0?hdr0:"",hdr1!=0?hdr1:"",hdr2!=0?hdr2:"",hdr3!=0?hdr3:""); + headers = curl_slist_append(headers,hdr0); + if ( hdr1 != 0 && hdr1[0] != 0 ) + headers = curl_slist_append(headers,hdr1); + if ( hdr2 != 0 && hdr2[0] != 0 ) + headers = curl_slist_append(headers,hdr2); + if ( hdr3 != 0 && hdr3[0] != 0 ) + headers = curl_slist_append(headers,hdr3); + } //headers = curl_slist_append(0,"Expect:"); + if ( headers != 0 ) + curl_easy_setopt(cHandle,CURLOPT_HTTPHEADER,headers); + //res = curl_easy_perform(cHandle); + memset(&chunk,0,sizeof(chunk)); + curl_easy_setopt(cHandle,CURLOPT_WRITEFUNCTION,WriteMemoryCallback); + curl_easy_setopt(cHandle,CURLOPT_WRITEDATA,(void *)&chunk); + curl_easy_perform(cHandle); + curl_easy_getinfo(cHandle,CURLINFO_RESPONSE_CODE,&code); + if ( headers != 0 ) + curl_slist_free_all(headers); + if ( code != 200 ) + printf("(%s) server responded with code %ld (%s)\n",url,code,chunk.memory); + return(chunk.memory); +} + +char *komodo_issuemethod(char *method,char *params,char *userpass) +{ + static void *cHandle; + char url[512],*retstr=0,postdata[8192]; + if ( strlen(params) < sizeof(postdata)-128 ) + { + if ( params == 0 ) + params = "[]"; + sprintf(url,"http://127.0.0.1:7771"); + sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); + retstr = curl_post(&cHandle,url,userpass,postdata,0,0,0,0); + } + return(retstr); +} + uint32_t komodo_txtime(uint256 hash) { CTransaction tx; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h new file mode 100644 index 000000000..2c61bbd0f --- /dev/null +++ b/src/komodo_gateway.h @@ -0,0 +1,24 @@ +/****************************************************************************** + * Copyright © 2014-2016 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. * + * * + ******************************************************************************/ + +void komodo_gateway_issuer() // "assetchain" +{ + +} + +void komodo_gateway_redeemer() // "KMD" +{ + +} \ No newline at end of file From b858fa74b4fe5327aed9f4ae94cdb8f5afb3c8a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:01:19 -0300 Subject: [PATCH 002/205] test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7511d165d..12ac0023c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -29,7 +29,7 @@ static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) { size_t realsize = (size * nmemb); struct MemoryStruct *mem = (struct MemoryStruct *)data; - mem->memory = (ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1); + mem->memory = (char *)((ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1)); if ( mem->memory != 0 ) { if ( ptr != 0 ) @@ -95,8 +95,8 @@ char *komodo_issuemethod(char *method,char *params,char *userpass) if ( strlen(params) < sizeof(postdata)-128 ) { if ( params == 0 ) - params = "[]"; - sprintf(url,"http://127.0.0.1:7771"); + params = (char *)"[]"; + sprintf(url,(char *)"http://127.0.0.1:7771"); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); retstr = curl_post(&cHandle,url,userpass,postdata,0,0,0,0); } From 05d3d5ff310a75950bbc5f64084c751cda59dcb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:02:16 -0300 Subject: [PATCH 003/205] test --- 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 12ac0023c..517d0d706 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -41,7 +41,7 @@ static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) return(realsize); } -void *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3) +char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3) { struct MemoryStruct chunk; CURL *cHandle; long code; struct curl_slist *headers = 0; if ( (cHandle= *cHandlep) == NULL ) From cc686fe52d74da01ab4a745a8443999bd6b34f2f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:08:22 -0300 Subject: [PATCH 004/205] test --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 303ba17fa..6152ffb40 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,7 +31,7 @@ LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a LIBBITCOIN_UNIVALUE=univalue/libbitcoin_univalue.a LIBBITCOINQT=qt/libbitcoinqt.a LIBSECP256K1=secp256k1/libsecp256k1.la -LIBZCASH=libzcash.a +LIBZCASH=libzcash.a -lcurl $(LIBSECP256K1): $(wildcard secp256k1/src/*) $(wildcard secp256k1/include/*) $(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F) From e9595d76d611b9a08baf53672078879f05bbe6ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:18:07 -0300 Subject: [PATCH 005/205] test --- src/komodo.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 37d9f6df6..a35b39af4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -41,7 +41,7 @@ pthread_mutex_t komodo_mutex; int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals) { - static FILE *fp; static int32_t errs,didinit; char fname[512]; int32_t ht,k,i,func; uint8_t num,pubkeys[64][33]; + static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); #else @@ -182,7 +182,7 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp) { - static uint256 zero; int32_t k,opretlen,nid,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; + static uint256 zero; int32_t opretlen,nid,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); @@ -258,10 +258,9 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { - static int32_t didinit; - char *scriptstr,*opreturnstr; uint64_t signedmask,voutmask; + uint64_t signedmask,voutmask; uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; - int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count,flag; + int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(); #ifdef KOMODO_ISSUER komodo_gateway_issuer(); From 8859397696a2ef7a5a8f35f977667995b41b96b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:24:14 -0300 Subject: [PATCH 006/205] test --- src/komodo.h | 3 ++- src/komodo_interest.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index a35b39af4..89dec6713 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -38,8 +38,9 @@ pthread_mutex_t komodo_mutex; #include "komodo_pax.h" #endif #include "komodo_notary.h" +#include "komodo_gateway.h" -int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals) +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals) { static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; #ifdef WIN32 diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 12aa420b5..b71178d15 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -46,6 +46,7 @@ uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest) } } } + return(0); } uint64_t komodo_moneysupply(int32_t height) From 09cc09abcb0290e456763a3430d9f5fa98a12539 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:26:15 -0300 Subject: [PATCH 007/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 89dec6713..630051089 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -24,7 +24,7 @@ #include #include "komodo_utils.h" -int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals); +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals); void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); From 6fbbb4cd5fae997c570de7981d6137b4c1c8741d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:35:06 -0300 Subject: [PATCH 008/205] test --- src/mini-gmp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mini-gmp.c b/src/mini-gmp.c index 54497ca72..204c53afc 100644 --- a/src/mini-gmp.c +++ b/src/mini-gmp.c @@ -70,8 +70,7 @@ see https://www.gnu.org/licenses/. */ #define GMP_MAX(a, b) ((a) > (b) ? (a) : (b)) #define gmp_assert_nocarry(x) do { \ - mp_limb_t __cy = x; if ( __cy != 0 ) \ - ; \ + mp_limb_t __cy = x; if ( __cy != 0 ) ; \ assert (__cy == 0); \ } while (0) From ba8f30436faf0bf20a4600903655af2bfd698995 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:36:22 -0300 Subject: [PATCH 009/205] test --- src/mini-gmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mini-gmp.c b/src/mini-gmp.c index 204c53afc..4cc08c27c 100644 --- a/src/mini-gmp.c +++ b/src/mini-gmp.c @@ -70,7 +70,7 @@ see https://www.gnu.org/licenses/. */ #define GMP_MAX(a, b) ((a) > (b) ? (a) : (b)) #define gmp_assert_nocarry(x) do { \ - mp_limb_t __cy = x; if ( __cy != 0 ) ; \ + mp_limb_t __cy = x; if ( __cy != 0 ) {} \ assert (__cy == 0); \ } while (0) From 7637aa7fb7fd7e7f38181a55260f39ef8562aceb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:44:59 -0300 Subject: [PATCH 010/205] test --- src/komodo_bitcoind.h | 12 ++++++++++-- src/komodo_utils.h | 2 +- src/main.cpp | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 517d0d706..ed12a175d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -107,7 +107,11 @@ uint32_t komodo_txtime(uint256 hash) { CTransaction tx; uint256 hashBlock; - if (!GetTransaction(hash, tx, hashBlock, true)) + if (!GetTransaction(hash, tx, +#ifndef KOMODO_ZCASH + Params().GetConsensus(), +#endif + hashBlock, true)) { //printf("null GetTransaction\n"); return(tx.nLockTime); @@ -158,7 +162,11 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) memset(pubkey33,0,33); if ( pindex != 0 ) { - if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex) != 0 ) + if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex, +#ifndef KOMODO_ZCASH + Params().GetConsensus(), +#endif + ) != 0 ) { komodo_block2pubkey33(pubkey33,block); } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ad935a691..7d540f746 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -736,7 +736,7 @@ int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr } for (i=0; i Date: Tue, 25 Oct 2016 12:46:59 -0300 Subject: [PATCH 011/205] test --- src/komodo.h | 4 ++-- src/komodo_bitcoind.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 630051089..dd8da4c8a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -282,7 +282,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) len = block.vtx[i].vout[j].scriptPubKey.size(); if ( len <= sizeof(scriptbuf) ) { - memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len); + memcpy(scriptbuf,&block.vtx[i].vout[j].scriptPubKey,len); notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight); if ( 0 && i > 0 ) { @@ -318,7 +318,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) len = block.vtx[i].vout[j].scriptPubKey.size(); if ( len <= sizeof(scriptbuf) ) { - memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len); + memcpy(scriptbuf,&block.vtx[i].vout[j].scriptPubKey,len); if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { memcpy(pubkeys[numvalid++],scriptbuf+1,33); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ed12a175d..9b659ae8e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -130,7 +130,7 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) int32_t komodo_block2height(CBlock *block) { - int32_t i,n,height = 0; uint8_t *ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data(); + int32_t i,n,height = 0; uint8_t *ptr = (uint8_t *)&block->vtx[0].vin[0].scriptSig; komodo_init(); if ( block->vtx[0].vin[0].scriptSig.size() > 5 ) { @@ -150,7 +150,7 @@ int32_t komodo_block2height(CBlock *block) void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) { - uint8_t *ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data(); + uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey; komodo_init(); memcpy(pubkey33,ptr+1,33); } @@ -164,7 +164,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) { if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex, #ifndef KOMODO_ZCASH - Params().GetConsensus(), + Params().GetConsensus() #endif ) != 0 ) { From 09019cdcf23c992f2688650720cca032382503cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:47:58 -0300 Subject: [PATCH 012/205] test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9b659ae8e..3c4fd6ca7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -162,9 +162,9 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) memset(pubkey33,0,33); if ( pindex != 0 ) { - if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex, + if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex #ifndef KOMODO_ZCASH - Params().GetConsensus() + ,Params().GetConsensus() #endif ) != 0 ) { From b5f08ccf9c2c244f2fabd087074ce8aaa03ffd3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 12:58:23 -0300 Subject: [PATCH 013/205] test --- src/komodo_notary.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 729c73f76..76ee06c10 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -135,6 +135,8 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) // -1 if not notary, 0 if notary, 1 if special notary struct knotary_entry *kp; int32_t numnotaries,modval = -1; *notaryidp = -1; + if ( height < 0 || height/KOMODO_ELECTION_GAP >= sizeof(Pubkeys)/sizeof(*Pubkeys) ) + return(-1); pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,Pubkeys[height/KOMODO_ELECTION_GAP].Notaries,pubkey33,33,kp); pthread_mutex_unlock(&komodo_mutex); From 438d3f359f3f000454828c9ba2e4624472342ca0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 13:25:07 -0300 Subject: [PATCH 014/205] test --- src/komodo_utils.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7d540f746..38e17ad3e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -906,3 +906,23 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_ memcpy(&script[offset],opret,opretlen); return(opretlen + offset); } + +void komodo_configfile(char *symbol,uint16_t port) +{ + FILE *fp; char fname[512],buf[128]; + sprintf(buf,"%s.conf",symbol); +#ifdef WIN32 + sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf); +#else + sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),buf); +#endif + if ( (fp= fopen(fname,"rb")) == 0 ) + { + if ( (fp= fopen(fname,"wb")) != 0 ) + { + fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%u\nrpcport=%u\nserver=1\n",rand(),rand(),port); + fclose(fp); + printf("Created (%s)\n",fname); + } + } +} From 9efac2fe27b6cad81fb821d63fd6236648129373 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 13:33:15 -0300 Subject: [PATCH 015/205] test --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 38e17ad3e..a8fa41d2a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -910,6 +910,7 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_ void komodo_configfile(char *symbol,uint16_t port) { FILE *fp; char fname[512],buf[128]; + srand((uin32_t)time(NULL)); sprintf(buf,"%s.conf",symbol); #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf); From 1e2b1c77a6556ed17db147768fc8fc73d555c773 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 13:40:08 -0300 Subject: [PATCH 016/205] 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 a8fa41d2a..aae909d42 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -910,7 +910,7 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_ void komodo_configfile(char *symbol,uint16_t port) { FILE *fp; char fname[512],buf[128]; - srand((uin32_t)time(NULL)); + srand((uint32_t)time(NULL)); sprintf(buf,"%s.conf",symbol); #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf); From 484f87773a9869e98c8f3645d4a3662f98af47ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 14:08:41 -0300 Subject: [PATCH 017/205] test --- src/komodo.h | 12 ++++++------ src/komodo_bitcoind.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index dd8da4c8a..e414a662e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -232,9 +232,9 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); - //for (k=0; k NOTARIZED_HEIGHT && *notarizedheightp < height ) { printf("ht.%d NOTARIZED.%d KMD.%s BTCTXID.%s (%s)\n",height,*notarizedheightp,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); @@ -250,7 +250,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; numpvals = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals); - //printf("vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); + printf("vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); } #endif } @@ -282,7 +282,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) len = block.vtx[i].vout[j].scriptPubKey.size(); if ( len <= sizeof(scriptbuf) ) { - memcpy(scriptbuf,&block.vtx[i].vout[j].scriptPubKey,len); + memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len); notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight); if ( 0 && i > 0 ) { @@ -318,7 +318,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) len = block.vtx[i].vout[j].scriptPubKey.size(); if ( len <= sizeof(scriptbuf) ) { - memcpy(scriptbuf,&block.vtx[i].vout[j].scriptPubKey,len); + memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len); if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { memcpy(pubkeys[numvalid++],scriptbuf+1,33); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3c4fd6ca7..884542f52 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -130,7 +130,7 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) int32_t komodo_block2height(CBlock *block) { - int32_t i,n,height = 0; uint8_t *ptr = (uint8_t *)&block->vtx[0].vin[0].scriptSig; + int32_t i,n,height = 0; uint8_t *ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data(); komodo_init(); if ( block->vtx[0].vin[0].scriptSig.size() > 5 ) { @@ -150,7 +150,7 @@ int32_t komodo_block2height(CBlock *block) void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) { - uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey; + uint8_t *ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data(); komodo_init(); memcpy(pubkey33,ptr+1,33); } From 0ac1f6fc8f7083e0a2ad3e18787277db0c0fc8a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 14:09:52 -0300 Subject: [PATCH 018/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index e414a662e..d866b24cd 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -183,7 +183,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp) { - static uint256 zero; int32_t opretlen,nid,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; + static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); From 6663a06db810db1ba2bb2ba9b9a3f9fec6b96f6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 14:14:27 -0300 Subject: [PATCH 019/205] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f0a78c0f2..83a79835a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1152,7 +1152,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (!view.HaveCoins(txin.prevout.hash)) { if (pfMissingInputs) *pfMissingInputs = true; - fprintf(stderr,"missing inputs\n"); + //fprintf(stderr,"missing inputs\n"); return false; } } From da00f2ddcb1e84b7437f3ae15acc1895674b0477 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 14:28:56 -0300 Subject: [PATCH 020/205] test --- src/komodo_bitcoind.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 884542f52..804c6333b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -150,7 +150,11 @@ int32_t komodo_block2height(CBlock *block) void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) { +#ifdef KOMODO_ZCASH uint8_t *ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data(); +#else + uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0]; +#endif komodo_init(); memcpy(pubkey33,ptr+1,33); } From 189d9dee6cdb703a67f68a2498e8519023c8222d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 14:32:58 -0300 Subject: [PATCH 021/205] test --- src/komodo.h | 8 ++++++++ src/komodo_bitcoind.h | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index d866b24cd..4e679d37a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -282,7 +282,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) len = block.vtx[i].vout[j].scriptPubKey.size(); if ( len <= sizeof(scriptbuf) ) { +#ifdef KOMODO_ZCASH memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len); +#else + memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); +#endif notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight); if ( 0 && i > 0 ) { @@ -318,7 +322,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) len = block.vtx[i].vout[j].scriptPubKey.size(); if ( len <= sizeof(scriptbuf) ) { +#ifdef KOMODO_ZCASH memcpy(scriptbuf,block.vtx[i].vout[j].scriptPubKey.data(),len); +#else + memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); +#endif if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { memcpy(pubkeys[numvalid++],scriptbuf+1,33); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 804c6333b..9fa0db9f8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -130,8 +130,13 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) int32_t komodo_block2height(CBlock *block) { - int32_t i,n,height = 0; uint8_t *ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data(); + int32_t i,n,height = 0; uint8_t *ptr; komodo_init(); +#ifdef KOMODO_ZCASH + ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data(); +#else + ptr = (uint8_t *)&block->vtx[0].vin[0].scriptSig[0]; +#endif if ( block->vtx[0].vin[0].scriptSig.size() > 5 ) { //for (i=0; i<6; i++) From fd1799a6318b7f2524837c3e2b8d6252f9d5c4cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 14:54:51 -0300 Subject: [PATCH 022/205] test --- src/komodo.h | 1 + src/komodo_bitcoind.h | 8 ++--- src/komodo_utils.h | 69 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 4e679d37a..3dc33977a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -31,6 +31,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n int32_t NOTARIZED_HEIGHT,Num_nutxos; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; +char USERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "komodo_bitcoind.h" #include "komodo_interest.h" diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9fa0db9f8..84904d451 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -88,17 +88,17 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * return(chunk.memory); } -char *komodo_issuemethod(char *method,char *params,char *userpass) +char *komodo_issuemethod(char *method,char *params) { - static void *cHandle; + static void *cHandle; extern char USERPASS[]; extern uint16_t BITCOIND_PORT; char url[512],*retstr=0,postdata[8192]; if ( strlen(params) < sizeof(postdata)-128 ) { if ( params == 0 ) params = (char *)"[]"; - sprintf(url,(char *)"http://127.0.0.1:7771"); + sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - retstr = curl_post(&cHandle,url,userpass,postdata,0,0,0,0); + retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } return(retstr); } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index aae909d42..380be4687 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -907,11 +907,40 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_ return(opretlen + offset); } +long _stripwhite(char *buf,int accept) +{ + int32_t i,j,c; + if ( buf == 0 || buf[0] == 0 ) + return(0); + for (i=j=0; buf[i]!=0; i++) + { + buf[j] = c = buf[i]; + if ( c == accept || (c != ' ' && c != '\n' && c != '\r' && c != '\t' && c != '\b') ) + j++; + } + buf[j] = 0; + return(j); +} + +char *parse_conf_line(char *line,char *field) +{ + line += strlen(field); + for (; *line!='='&&*line!=0; line++) + break; + if ( *line == 0 ) + return(0); + if ( *line == '=' ) + line++; + _stripwhite(line,0); + return(clonestr(line)); +} + void komodo_configfile(char *symbol,uint16_t port) { - FILE *fp; char fname[512],buf[128]; + FILE *fp; char fname[512],buf[128],line[4096],*rpcuser,*rpcpassword,*rpcport,*retstr; srand((uint32_t)time(NULL)); sprintf(buf,"%s.conf",symbol); + BITCOIND_PORT = port; #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf); #else @@ -926,4 +955,42 @@ void komodo_configfile(char *symbol,uint16_t port) printf("Created (%s)\n",fname); } } + else + { + rpcuser = rpcpassword = rpcport = 0; + while ( fgets(line,sizeof(line),fp) != 0 ) + { + if ( line[0] == '#' ) + continue; + //printf("line.(%s) %p %p\n",line,strstr(line,"rpcuser"),strstr(line,"rpcpassword")); + if ( (str= strstr(line,"rpcuser")) != 0 ) + rpcuser = parse_conf_line(str,"rpcuser"); + else if ( (str= strstr(line,"rpcpassword")) != 0 ) + rpcpassword = parse_conf_line(str,"rpcpassword"); + else if ( (str= strstr(line,"rpcport")) != 0 ) + rpcport = parse_conf_line(str,"rpcport"); + } + if ( rpcuser != 0 && rpcpassword != 0 ) + { + sprintf(USERPASS,"%s:%s",rpcuser,rpcpassword); + } + if ( rpcport != 0 ) + { + if ( port != atoi(rpcport) ) + printf("port.%u mismatch (%s)\n",port,rpcport); + //if ( serverport[0] == 0 ) + // sprintf(serverport,"127.0.0.1:%s",rpcport); + free(rpcport); + } + if ( rpcuser != 0 ) + free(rpcuser); + if ( rpcpassword != 0 ) + free(rpcpassword); + fclose(fp); + } + if ( (retstr= komodo_issuemethod("getinfo",0)) != 0 ) + { + printf("GETINFO.%s (%s)\n",symbol,retstr); + free(retstr); + } } From 51d5c72a2be7e42a29d7f98a376c4119b4174d9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 14:56:00 -0300 Subject: [PATCH 023/205] test --- 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 84904d451..3069e2dd2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -96,7 +96,7 @@ char *komodo_issuemethod(char *method,char *params) { if ( params == 0 ) params = (char *)"[]"; - sprintf(url,(char *)"http://127.0.0.1:%u",port); + sprintf(url,(char *)"http://127.0.0.1:%u",BITCOIND_PORT); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } From 2c36c760e57965584bbbdfd0c2d8e2962e0c587a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 14:57:31 -0300 Subject: [PATCH 024/205] test --- src/komodo_utils.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 380be4687..2215338f7 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -922,6 +922,22 @@ long _stripwhite(char *buf,int accept) return(j); } +char *clonestr(char *str) +{ + char *clone; + if ( str == 0 || str[0] == 0 ) + { + printf("warning cloning nullstr.%p\n",str); +#ifdef __APPLE__ + while ( 1 ) sleep(1); +#endif + str = (char *)""; + } + clone = (char *)malloc(strlen(str)+16); + strcpy(clone,str); + return(clone); +} + char *parse_conf_line(char *line,char *field) { line += strlen(field); From d84012ad44919de28dbb280c83cf0a41239fd234 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:02:20 -0300 Subject: [PATCH 025/205] test --- src/komodo.h | 1 + src/komodo_bitcoind.h | 2 +- src/komodo_utils.h | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 3dc33977a..0791d7db5 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -27,6 +27,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals); void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); +char *komodo_issuemethod(char *method,char *params); int32_t NOTARIZED_HEIGHT,Num_nutxos; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3069e2dd2..4356ed32d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -90,7 +90,7 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * char *komodo_issuemethod(char *method,char *params) { - static void *cHandle; extern char USERPASS[]; extern uint16_t BITCOIND_PORT; + static void *cHandle; extern char USERPASS[1024]; extern uint16_t BITCOIND_PORT; char url[512],*retstr=0,postdata[8192]; if ( strlen(params) < sizeof(postdata)-128 ) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2215338f7..c299910e4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -953,7 +953,8 @@ char *parse_conf_line(char *line,char *field) void komodo_configfile(char *symbol,uint16_t port) { - FILE *fp; char fname[512],buf[128],line[4096],*rpcuser,*rpcpassword,*rpcport,*retstr; + extern uint16_t BITCOIND_PORT; + FILE *fp; char fname[512],buf[128],line[4096],*str,*rpcuser,*rpcpassword,*rpcport,*retstr; srand((uint32_t)time(NULL)); sprintf(buf,"%s.conf",symbol); BITCOIND_PORT = port; From 46beb55e21de61091152263b16e9e4086e4cc28d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:04:07 -0300 Subject: [PATCH 026/205] test --- src/komodo.h | 2 +- src/komodo_utils.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0791d7db5..5abb2f7f9 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -22,7 +22,6 @@ #include #include #include -#include "komodo_utils.h" void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals); void komodo_init(); @@ -34,6 +33,7 @@ uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; char USERPASS[1024]; uint16_t BITCOIND_PORT = 7771; +#include "komodo_utils.h" #include "komodo_bitcoind.h" #include "komodo_interest.h" #ifdef KOMODO_PAX diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c299910e4..f1e70000f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -980,12 +980,12 @@ void komodo_configfile(char *symbol,uint16_t port) if ( line[0] == '#' ) continue; //printf("line.(%s) %p %p\n",line,strstr(line,"rpcuser"),strstr(line,"rpcpassword")); - if ( (str= strstr(line,"rpcuser")) != 0 ) - rpcuser = parse_conf_line(str,"rpcuser"); - else if ( (str= strstr(line,"rpcpassword")) != 0 ) - rpcpassword = parse_conf_line(str,"rpcpassword"); - else if ( (str= strstr(line,"rpcport")) != 0 ) - rpcport = parse_conf_line(str,"rpcport"); + if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) + rpcuser = parse_conf_line(str,(char *)"rpcuser"); + else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) + rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); + else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) + rpcport = parse_conf_line(str,(char *)"rpcport"); } if ( rpcuser != 0 && rpcpassword != 0 ) { From 978a39245e1fd3fd8e0fcdfb5f47400ea94c733e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:05:39 -0300 Subject: [PATCH 027/205] 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 f1e70000f..54acff61b 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1005,7 +1005,7 @@ void komodo_configfile(char *symbol,uint16_t port) free(rpcpassword); fclose(fp); } - if ( (retstr= komodo_issuemethod("getinfo",0)) != 0 ) + if ( (retstr= komodo_issuemethod((char *)"getinfo",0)) != 0 ) { printf("GETINFO.%s (%s)\n",symbol,retstr); free(retstr); From 365378b529c6de03b973320d91099ac79b3c79d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:09:14 -0300 Subject: [PATCH 028/205] test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4356ed32d..55f7d5e08 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -92,10 +92,10 @@ char *komodo_issuemethod(char *method,char *params) { static void *cHandle; extern char USERPASS[1024]; extern uint16_t BITCOIND_PORT; char url[512],*retstr=0,postdata[8192]; + if ( params == 0 || params[0] == 0 ) + params = (char *)"[]"; if ( strlen(params) < sizeof(postdata)-128 ) { - if ( params == 0 ) - params = (char *)"[]"; sprintf(url,(char *)"http://127.0.0.1:%u",BITCOIND_PORT); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); From a7798b0d98302f0fc73a29c22bcecc906ebda92b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:15:00 -0300 Subject: [PATCH 029/205] test --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 54acff61b..8f921e91b 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -979,7 +979,7 @@ void komodo_configfile(char *symbol,uint16_t port) { if ( line[0] == '#' ) continue; - //printf("line.(%s) %p %p\n",line,strstr(line,"rpcuser"),strstr(line,"rpcpassword")); + printf("line.(%s) %p %p\n",line,strstr(line,"rpcuser"),strstr(line,"rpcpassword")); if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) rpcuser = parse_conf_line(str,(char *)"rpcuser"); else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) @@ -1007,7 +1007,7 @@ void komodo_configfile(char *symbol,uint16_t port) } if ( (retstr= komodo_issuemethod((char *)"getinfo",0)) != 0 ) { - printf("GETINFO.%s (%s)\n",symbol,retstr); + printf("GETINFO.%s (%s) USERPASS.%s\n",symbol,retstr,USERPASS); free(retstr); } } From 83c2d095e7f102c7b93833bf75bf8e2c5d9ba3ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:19:28 -0300 Subject: [PATCH 030/205] test --- src/komodo_utils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8f921e91b..7855e292f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -947,6 +947,8 @@ char *parse_conf_line(char *line,char *field) return(0); if ( *line == '=' ) line++; + while ( line[strlen(line)-1] == '\r' || line[strlen(line)-1] == '\n' || line[strlen(line)-1] == ' ' ) + line[strlen(line)-1] == 0; _stripwhite(line,0); return(clonestr(line)); } From ea3631c602f0f451bbf61e96a96e17c0993f527c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:21:03 -0300 Subject: [PATCH 031/205] test --- src/komodo_utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7855e292f..2a5d61760 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -949,6 +949,7 @@ char *parse_conf_line(char *line,char *field) line++; while ( line[strlen(line)-1] == '\r' || line[strlen(line)-1] == '\n' || line[strlen(line)-1] == ' ' ) line[strlen(line)-1] == 0; + printf("LINE.(%s)\n",line); _stripwhite(line,0); return(clonestr(line)); } @@ -981,7 +982,7 @@ void komodo_configfile(char *symbol,uint16_t port) { if ( line[0] == '#' ) continue; - printf("line.(%s) %p %p\n",line,strstr(line,"rpcuser"),strstr(line,"rpcpassword")); + printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword")); if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) rpcuser = parse_conf_line(str,(char *)"rpcuser"); else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) From 5ae7efc18beb149af110746426f2ef0327c0f7e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:22:01 -0300 Subject: [PATCH 032/205] 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 2a5d61760..c29bd5ce4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -948,7 +948,7 @@ char *parse_conf_line(char *line,char *field) if ( *line == '=' ) line++; while ( line[strlen(line)-1] == '\r' || line[strlen(line)-1] == '\n' || line[strlen(line)-1] == ' ' ) - line[strlen(line)-1] == 0; + line[strlen(line)-1] = 0; printf("LINE.(%s)\n",line); _stripwhite(line,0); return(clonestr(line)); From d15d37d20bcce9df618079e866c8ad59e60c125b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:26:20 -0300 Subject: [PATCH 033/205] test --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c29bd5ce4..c93aa162f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -990,6 +990,7 @@ void komodo_configfile(char *symbol,uint16_t port) else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) rpcport = parse_conf_line(str,(char *)"rpcport"); } + printf("rpcuser.(%s) rpcpassword.(%s) port.(%s)\n",rpcuser,rpcpassword,rpcport); if ( rpcuser != 0 && rpcpassword != 0 ) { sprintf(USERPASS,"%s:%s",rpcuser,rpcpassword); From 4d4aa3ec218a69e371259a28f1be0c426abc8286 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:30:17 -0300 Subject: [PATCH 034/205] test --- src/komodo_bitcoind.h | 1 + src/komodo_utils.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 55f7d5e08..f986e412e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -98,6 +98,7 @@ char *komodo_issuemethod(char *method,char *params) { sprintf(url,(char *)"http://127.0.0.1:%u",BITCOIND_PORT); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); + printf("postdata.(%s) USERPASS.(%s)\n",postdata,USERPASS); retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } return(retstr); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c93aa162f..18dce0029 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -990,7 +990,6 @@ void komodo_configfile(char *symbol,uint16_t port) else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) rpcport = parse_conf_line(str,(char *)"rpcport"); } - printf("rpcuser.(%s) rpcpassword.(%s) port.(%s)\n",rpcuser,rpcpassword,rpcport); if ( rpcuser != 0 && rpcpassword != 0 ) { sprintf(USERPASS,"%s:%s",rpcuser,rpcpassword); @@ -1003,6 +1002,7 @@ void komodo_configfile(char *symbol,uint16_t port) // sprintf(serverport,"127.0.0.1:%s",rpcport); free(rpcport); } + printf("rpcuser.(%s) rpcpassword.(%s) port.(%s) USERPASS.(%s) port.%u\n",rpcuser,rpcpassword,rpcport,USERPASS,atoi(rpcport!=0?rpcport:0)); if ( rpcuser != 0 ) free(rpcuser); if ( rpcpassword != 0 ) From e78fb5d33807dc90b4bd65bc5c9f335bb1f2197d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:34:23 -0300 Subject: [PATCH 035/205] test --- src/komodo_bitcoind.h | 4 ++-- src/komodo_utils.h | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f986e412e..c663a333a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -90,8 +90,7 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * char *komodo_issuemethod(char *method,char *params) { - static void *cHandle; extern char USERPASS[1024]; extern uint16_t BITCOIND_PORT; - char url[512],*retstr=0,postdata[8192]; + static void *cHandle; char url[512],*retstr=0,postdata[8192]; if ( params == 0 || params[0] == 0 ) params = (char *)"[]"; if ( strlen(params) < sizeof(postdata)-128 ) @@ -103,6 +102,7 @@ char *komodo_issuemethod(char *method,char *params) } return(retstr); } +//curl --url "http://127.0.0.1:14555" --data "{\"method\":\"getinfo\",\"params\":[]}" uint32_t komodo_txtime(uint256 hash) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 18dce0029..baaa90dbf 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -949,15 +949,14 @@ char *parse_conf_line(char *line,char *field) line++; while ( line[strlen(line)-1] == '\r' || line[strlen(line)-1] == '\n' || line[strlen(line)-1] == ' ' ) line[strlen(line)-1] = 0; - printf("LINE.(%s)\n",line); + //printf("LINE.(%s)\n",line); _stripwhite(line,0); return(clonestr(line)); } void komodo_configfile(char *symbol,uint16_t port) { - extern uint16_t BITCOIND_PORT; - FILE *fp; char fname[512],buf[128],line[4096],*str,*rpcuser,*rpcpassword,*rpcport,*retstr; + FILE *fp; char fname[512],buf[128],line[4096],*str,*rpcuser,*rpcpassword,*rpcport; srand((uint32_t)time(NULL)); sprintf(buf,"%s.conf",symbol); BITCOIND_PORT = port; @@ -982,7 +981,7 @@ void komodo_configfile(char *symbol,uint16_t port) { if ( line[0] == '#' ) continue; - printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword")); + //printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword")); if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) rpcuser = parse_conf_line(str,(char *)"rpcuser"); else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) @@ -1009,9 +1008,9 @@ void komodo_configfile(char *symbol,uint16_t port) free(rpcpassword); fclose(fp); } - if ( (retstr= komodo_issuemethod((char *)"getinfo",0)) != 0 ) + /*if ( (retstr= komodo_issuemethod((char *)"getinfo",0)) != 0 ) { printf("GETINFO.%s (%s) USERPASS.%s\n",symbol,retstr,USERPASS); free(retstr); - } + }*/ } From 4556286725abbc2488683d660838022bc9733636 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 15:44:25 -0300 Subject: [PATCH 036/205] test --- src/komodo_bitcoind.h | 2 +- src/komodo_utils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c663a333a..febca0c23 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -102,7 +102,7 @@ char *komodo_issuemethod(char *method,char *params) } return(retstr); } -//curl --url "http://127.0.0.1:14555" --data "{\"method\":\"getinfo\",\"params\":[]}" +//curl --url "http://127.0.0.1:14555" --user "user782512472:pass1476445872" --data "{\"method\":\"getinfo\",\"params\":[]}" uint32_t komodo_txtime(uint256 hash) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index baaa90dbf..29dae5475 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1001,7 +1001,7 @@ void komodo_configfile(char *symbol,uint16_t port) // sprintf(serverport,"127.0.0.1:%s",rpcport); free(rpcport); } - printf("rpcuser.(%s) rpcpassword.(%s) port.(%s) USERPASS.(%s) port.%u\n",rpcuser,rpcpassword,rpcport,USERPASS,atoi(rpcport!=0?rpcport:0)); + printf("rpcuser.(%s) rpcpassword.(%s) port.(%s) USERPASS.(%s) port.%u vs %u\n",rpcuser,rpcpassword,rpcport,USERPASS,atoi(rpcport!=0?rpcport:0),port); if ( rpcuser != 0 ) free(rpcuser); if ( rpcpassword != 0 ) From c0160cc3774a3f559dee5bd8dbe516be2c1b9fb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 16:11:13 -0300 Subject: [PATCH 037/205] 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 29dae5475..ccbf56583 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -969,7 +969,7 @@ void komodo_configfile(char *symbol,uint16_t port) { if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%u\nrpcport=%u\nserver=1\n",rand(),rand(),port); + fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%u\nrpcport=%u\nserver=1\ntxindex=1\n",rand(),rand(),port); fclose(fp); printf("Created (%s)\n",fname); } From 46ff7513444427c6ba685a617f2599f1d88917a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 18:09:30 -0300 Subject: [PATCH 038/205] test --- src/komodo_bitcoind.h | 2 +- src/komodo_utils.h | 79 ++++++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index febca0c23..4793ec968 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -102,7 +102,7 @@ char *komodo_issuemethod(char *method,char *params) } return(retstr); } -//curl --url "http://127.0.0.1:14555" --user "user782512472:pass1476445872" --data "{\"method\":\"getinfo\",\"params\":[]}" +//curl --url "http://127.0.0.1:13033" --user "user1557335368:pass111720054" --data "{\"method\":\"getinfo\",\"params\":[]}" uint32_t komodo_txtime(uint256 hash) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ccbf56583..b7e05eb86 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -976,41 +976,50 @@ void komodo_configfile(char *symbol,uint16_t port) } else { - rpcuser = rpcpassword = rpcport = 0; - while ( fgets(line,sizeof(line),fp) != 0 ) - { - if ( line[0] == '#' ) - continue; - //printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword")); - if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) - rpcuser = parse_conf_line(str,(char *)"rpcuser"); - else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) - rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); - else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) - rpcport = parse_conf_line(str,(char *)"rpcport"); - } - if ( rpcuser != 0 && rpcpassword != 0 ) - { - sprintf(USERPASS,"%s:%s",rpcuser,rpcpassword); - } - if ( rpcport != 0 ) - { - if ( port != atoi(rpcport) ) - printf("port.%u mismatch (%s)\n",port,rpcport); - //if ( serverport[0] == 0 ) - // sprintf(serverport,"127.0.0.1:%s",rpcport); - free(rpcport); - } - printf("rpcuser.(%s) rpcpassword.(%s) port.(%s) USERPASS.(%s) port.%u vs %u\n",rpcuser,rpcpassword,rpcport,USERPASS,atoi(rpcport!=0?rpcport:0),port); - if ( rpcuser != 0 ) - free(rpcuser); - if ( rpcpassword != 0 ) - free(rpcpassword); fclose(fp); + strcpy(fname,GetDataDir(false).string().c_str()); +#ifdef WIN32 + while ( fname[strlen(fname)-1] != '\\' ) + fname[strlen(fname)-1] = 0; + strcat(fname,".komodo/komodo.conf"); +#else + while ( fname[strlen(fname)-1] != '/' ) + fname[strlen(fname)-1] = 0; + strcat(fname,".komodo/komodo.conf"); +#endif + if ( (fp= fopen(fname,"rb")) != 0 ) + { + rpcuser = rpcpassword = rpcport = 0; + while ( fgets(line,sizeof(line),fp) != 0 ) + { + if ( line[0] == '#' ) + continue; + //printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword")); + if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) + rpcuser = parse_conf_line(str,(char *)"rpcuser"); + else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) + rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); + else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) + rpcport = parse_conf_line(str,(char *)"rpcport"); + } + if ( rpcuser != 0 && rpcpassword != 0 ) + { + sprintf(USERPASS,"%s:%s",rpcuser,rpcpassword); + } + if ( rpcport != 0 ) + { + if ( port != atoi(rpcport) ) + printf("port.%u mismatch (%s)\n",port,rpcport); + //if ( serverport[0] == 0 ) + // sprintf(serverport,"127.0.0.1:%s",rpcport); + free(rpcport); + } + printf("rpcuser.(%s) rpcpassword.(%s) port.(%s) USERPASS.(%s) port.%u vs %u\n",rpcuser,rpcpassword,rpcport,USERPASS,atoi(rpcport!=0?rpcport:0),port); + if ( rpcuser != 0 ) + free(rpcuser); + if ( rpcpassword != 0 ) + free(rpcpassword); + fclose(fp); + } else printf("couldnt open.(%s)\n",fname); } - /*if ( (retstr= komodo_issuemethod((char *)"getinfo",0)) != 0 ) - { - printf("GETINFO.%s (%s) USERPASS.%s\n",symbol,retstr,USERPASS); - free(retstr); - }*/ } From 62b751ab2ce04e6b1b0c886f8dadf391233f0424 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 18:13:50 -0300 Subject: [PATCH 039/205] test --- src/komodo_utils.h | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index b7e05eb86..9e6e626a9 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -956,7 +956,7 @@ char *parse_conf_line(char *line,char *field) void komodo_configfile(char *symbol,uint16_t port) { - FILE *fp; char fname[512],buf[128],line[4096],*str,*rpcuser,*rpcpassword,*rpcport; + FILE *fp; char fname[512],buf[128],line[4096],*str,*rpcuser,*rpcpassword; srand((uint32_t)time(NULL)); sprintf(buf,"%s.conf",symbol); BITCOIND_PORT = port; @@ -987,9 +987,10 @@ void komodo_configfile(char *symbol,uint16_t port) fname[strlen(fname)-1] = 0; strcat(fname,".komodo/komodo.conf"); #endif + printf("KOMODO.(%s)\n",fname); if ( (fp= fopen(fname,"rb")) != 0 ) { - rpcuser = rpcpassword = rpcport = 0; + rpcuser = rpcpassword = 0; while ( fgets(line,sizeof(line),fp) != 0 ) { if ( line[0] == '#' ) @@ -999,22 +1000,12 @@ void komodo_configfile(char *symbol,uint16_t port) rpcuser = parse_conf_line(str,(char *)"rpcuser"); else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); - else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) - rpcport = parse_conf_line(str,(char *)"rpcport"); } if ( rpcuser != 0 && rpcpassword != 0 ) { sprintf(USERPASS,"%s:%s",rpcuser,rpcpassword); } - if ( rpcport != 0 ) - { - if ( port != atoi(rpcport) ) - printf("port.%u mismatch (%s)\n",port,rpcport); - //if ( serverport[0] == 0 ) - // sprintf(serverport,"127.0.0.1:%s",rpcport); - free(rpcport); - } - printf("rpcuser.(%s) rpcpassword.(%s) port.(%s) USERPASS.(%s) port.%u vs %u\n",rpcuser,rpcpassword,rpcport,USERPASS,atoi(rpcport!=0?rpcport:0),port); + printf("rpcuser.(%s) rpcpassword.(%s) USERPASS.(%s) %u\n",rpcuser,rpcpassword,USERPASS,port); if ( rpcuser != 0 ) free(rpcuser); if ( rpcpassword != 0 ) From 3c0f5d94ddda1640cb2a0deb7274c3b49c9e419d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 18:19:15 -0300 Subject: [PATCH 040/205] test --- src/komodo.h | 2 +- src/komodo_bitcoind.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 5abb2f7f9..abf999069 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -26,7 +26,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals); void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); -char *komodo_issuemethod(char *method,char *params); +char *komodo_issuemethod(char *method,char *params,uint16_t port); int32_t NOTARIZED_HEIGHT,Num_nutxos; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4793ec968..ec352176a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -88,14 +88,14 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * return(chunk.memory); } -char *komodo_issuemethod(char *method,char *params) +char *komodo_issuemethod(char *method,char *params,uint16_t port) { static void *cHandle; char url[512],*retstr=0,postdata[8192]; if ( params == 0 || params[0] == 0 ) params = (char *)"[]"; if ( strlen(params) < sizeof(postdata)-128 ) { - sprintf(url,(char *)"http://127.0.0.1:%u",BITCOIND_PORT); + sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); printf("postdata.(%s) USERPASS.(%s)\n",postdata,USERPASS); retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); From b05863f5bd589a0080541eda2809e2a72bce3597 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 18:39:53 -0300 Subject: [PATCH 041/205] test --- src/komodo_bitcoind.h | 2 +- src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ec352176a..431f9f2bb 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -97,7 +97,7 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - printf("postdata.(%s) USERPASS.(%s)\n",postdata,USERPASS); + //printf("postdata.(%s) USERPASS.(%s)\n",postdata,USERPASS); retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } return(retstr); diff --git a/src/miner.cpp b/src/miner.cpp index 6afed045d..41a4f9f84 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -335,7 +335,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) //txNew.nLockTime = (uint32_t)time(NULL) - 60; txNew.vin.resize(1); txNew.vin[0].prevout.SetNull(); - int32_t i,opretlen; uint8_t opret[8192],*ptr; + int32_t i,opretlen; uint8_t opret[256],*ptr; if ( (opretlen= komodo_pax_opreturn(opret,sizeof(opret))) > 0 ) { txNew.vout.resize(2); From c2b50ce09259768077a00fcfc8bdbce3bb803702 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:04:08 -0300 Subject: [PATCH 042/205] test --- src/komodo_bitcoind.h | 209 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 207 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 431f9f2bb..fbebb0255 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -24,6 +24,210 @@ #endif struct MemoryStruct { char *memory; size_t size; }; +struct return_string { char *ptr; size_t len; }; + +// return data from the server +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_SSL (1<<0) +#define CURL_GLOBAL_WIN32 (1<<1) + + +size_t accumulate(void *ptr, size_t size, size_t nmemb, struct return_string *s); +void init_string(struct return_string *s); + + +/************************************************************************ + * + * return the current system time in milliseconds + * + ************************************************************************/ + +#define EXTRACT_BITCOIND_RESULT // if defined, ensures error is null and returns the "result" field +#ifdef EXTRACT_BITCOIND_RESULT + +/************************************************************************ + * + * perform post processing of the results + * + ************************************************************************/ + +char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *params) +{ + long i,j,len; char *retstr = 0; cJSON *json,*result,*error; + //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); + if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) + { + if ( strcmp(command,"signrawtransaction") != 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); + return(rpcstr); + } + json = cJSON_Parse(rpcstr); + if ( json == 0 ) + { + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s can't parse.(%s) params.(%s)\n",debugstr,command,rpcstr,params); + free(rpcstr); + return(0); + } + result = cJSON_GetObjectItem(json,"result"); + error = cJSON_GetObjectItem(json,"error"); + if ( error != 0 && result != 0 ) + { + if ( (error->type&0xff) == cJSON_NULL && (result->type&0xff) != cJSON_NULL ) + { + retstr = cJSON_Print(result); + len = strlen(retstr); + if ( retstr[0] == '"' && retstr[len-1] == '"' ) + { + for (i=1,j=0; itype&0xff) != cJSON_NULL || (result->type&0xff) != cJSON_NULL ) + { + if ( strcmp(command,"signrawtransaction") != 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC (%s) error.%s\n",debugstr,command,rpcstr); + } + free(rpcstr); + } else retstr = rpcstr; + free_json(json); + //fprintf(stderr,"<<<<<<<<<<< bitcoind_RPC: postprocess returns.(%s)\n",retstr); + return(retstr); +} +#endif + +/************************************************************************ + * + * perform the query + * + ************************************************************************/ + + +char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params) +{ + static int didinit,count,count2; static double elapsedsum,elapsedsum2; + struct curl_slist *headers = NULL; struct return_string s; CURLcode res; CURL *curl_handle; + char *bracket0,*bracket1,*databuf = 0; long len; int32_t specialcase,numretries; double starttime; + if ( didinit == 0 ) + { + didinit = 1; + curl_global_init(CURL_GLOBAL_ALL); //init the curl session + } + numretries = 0; + if ( debugstr != 0 && strcmp(debugstr,"BTCD") == 0 && command != 0 && strcmp(command,"SuperNET") == 0 ) + specialcase = 1; + else specialcase = 0; + if ( url[0] == 0 ) + strcpy(url,"http://127.0.0.1:7876/nxt"); + if ( specialcase != 0 && 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: debug.(%s) url.(%s) command.(%s) params.(%s)\n",debugstr,url,command,params); +try_again: + if ( retstrp != 0 ) + *retstrp = 0; + starttime = OS_milliseconds(); + curl_handle = curl_easy_init(); + init_string(&s); + headers = curl_slist_append(0,"Expect:"); + + curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); + curl_easy_setopt(curl_handle,CURLOPT_URL, url); + curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulate); // send all data to this function + curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback + curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash + curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback + if ( strncmp(url,"https",5) == 0 ) + { + curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYPEER,0); + curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYHOST,0); + } + if ( userpass != 0 ) + curl_easy_setopt(curl_handle,CURLOPT_USERPWD, userpass); + databuf = 0; + if ( params != 0 ) + { + if ( command != 0 && specialcase == 0 ) + { + len = strlen(params); + if ( len > 0 && params[0] == '[' && params[len-1] == ']' ) { + bracket0 = bracket1 = (char *)""; + } + else + { + bracket0 = (char *)"["; + bracket1 = (char *)"]"; + } + + databuf = (char *)malloc(256 + strlen(command) + strlen(params)); + sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); + //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + // + } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); + curl_easy_setopt(curl_handle,CURLOPT_POST,1L); + if ( databuf != 0 ) + curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,databuf); + else curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,params); + } + //laststart = milliseconds(); + res = curl_easy_perform(curl_handle); + curl_slist_free_all(headers); + curl_easy_cleanup(curl_handle); + if ( databuf != 0 ) // clean up temporary buffer + { + free(databuf); + databuf = 0; + } + if ( res != CURLE_OK ) + { + numretries++; + if ( specialcase != 0 ) + { + printf("<<<<<<<<<<< bitcoind_RPC.(%s): BTCD.%s timeout params.(%s) s.ptr.(%s) err.%d\n",url,command,params,s.ptr,res); + free(s.ptr); + return(0); + } + else if ( numretries >= 5 ) + { + printf("Maximum number of retries exceeded!\n"); + free(s.ptr); + return(0); + } + printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries); + free(s.ptr); + sleep((1< (%s)\n",params,s.ptr); + count2++; + elapsedsum2 += (OS_milliseconds() - starttime); + if ( (count2 % 10000) == 0) + printf("%d: ave %9.6f | elapsed %.3f millis | NXT calls.(%s) cmd.(%s)\n",count2,elapsedsum2/count2,(double)(OS_milliseconds() - starttime),url,command); + return(s.ptr); + } + } + printf("bitcoind_RPC: impossible case\n"); + free(s.ptr); + return(0); +} static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) { @@ -90,7 +294,7 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * char *komodo_issuemethod(char *method,char *params,uint16_t port) { - static void *cHandle; char url[512],*retstr=0,postdata[8192]; + static void *cHandle; char url[512],*retstr=0,*retstr2,postdata[8192]; if ( params == 0 || params[0] == 0 ) params = (char *)"[]"; if ( strlen(params) < sizeof(postdata)-128 ) @@ -98,7 +302,8 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port) sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); //printf("postdata.(%s) USERPASS.(%s)\n",postdata,USERPASS); - retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); + retstr2 = bitcoind_RPC(&retstr,"debug",url,USERPASS,method,params); + //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } return(retstr); } From 3a2b2b45b6029775b959e3451a2840646d162fa1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:06:27 -0300 Subject: [PATCH 043/205] test --- src/cJSON.c | 1128 ++++++++++++++++++++++++++++++++++++++++++++ src/cJSON.h | 234 +++++++++ src/komodo_utils.h | 1 + 3 files changed, 1363 insertions(+) create mode 100755 src/cJSON.c create mode 100755 src/cJSON.h diff --git a/src/cJSON.c b/src/cJSON.c new file mode 100755 index 000000000..5035f9a9b --- /dev/null +++ b/src/cJSON.c @@ -0,0 +1,1128 @@ + +/* + Copyright (c) 2009 Dave Gamble + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +/* cJSON */ +/* JSON parser in C. */ +#include + +#include "../includes/cJSON.h" + +#ifndef DBL_EPSILON +#define DBL_EPSILON 2.2204460492503131E-16 +#endif + +static const char *ep; + +long stripquotes(char *str) +{ + long len,offset; + if ( str == 0 ) + return(0); + len = strlen(str); + if ( str[0] == '"' && str[len-1] == '"' ) + str[len-1] = 0, offset = 1; + else offset = 0; + return(offset); +} + +const char *cJSON_GetErrorPtr(void) {return ep;} + +static int32_t cJSON_strcasecmp(const char *s1,const char *s2) +{ + if (!s1) return (s1==s2)?0:1;if (!s2) return 1; + for(; tolower((int32_t)(*s1)) == tolower((int32_t)(*s2)); ++s1, ++s2) if(*s1 == 0) return 0; + return tolower((int32_t)(*(const unsigned char *)s1)) - tolower((int32_t)(*(const unsigned char *)s2)); +} + +static void *(*cJSON_malloc)(size_t sz) = malloc; +static void (*cJSON_free)(void *ptr) = free; + +static char* cJSON_strdup(const char* str) +{ + size_t len; + char* copy; + + len = strlen(str) + 1; + if (!(copy = (char*)cJSON_malloc(len+1))) return 0; + memcpy(copy,str,len); + return copy; +} + +void cJSON_InitHooks(cJSON_Hooks* hooks) +{ + if (!hooks) { /* Reset hooks */ + cJSON_malloc = malloc; + cJSON_free = free; + return; + } + + cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc; + cJSON_free = (hooks->free_fn)?hooks->free_fn:free; +} + +/* Internal constructor. */ +static cJSON *cJSON_New_Item(void) +{ + cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON)); + if (node) memset(node,0,sizeof(cJSON)); + return node; +} + +/* Delete a cJSON structure. */ +void cJSON_Delete(cJSON *c) +{ + cJSON *next; + while (c) + { + next=c->next; + if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child); + if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring); + if (c->string) cJSON_free(c->string); + cJSON_free(c); + c=next; + } +} + +/* Parse the input text to generate a number, and populate the result into item. */ +static const char *parse_number(cJSON *item,const char *num) +{ + double n=0,sign=1,scale=0;int32_t subscale=0,signsubscale=1; + + if (*num=='-') sign=-1,num++; /* Has sign? */ + if (*num=='0') num++; /* is zero */ + if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */ + if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */ + if (*num=='e' || *num=='E') /* Exponent? */ + { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */ + while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */ + } + + n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */ + + item->valuedouble=n; + item->valueint=(int64_t)n; + item->type=cJSON_Number; + return num; +} + +/* Render the number nicely from the given item into a string. */ +static char *print_number(cJSON *item) +{ + char *str; + double d = item->valuedouble; + if ( fabs(((double)item->valueint) - d) <= DBL_EPSILON && d >= (1. - DBL_EPSILON) && d < (1LL << 62) )//d <= INT_MAX && d >= INT_MIN ) + { + str = (char *)cJSON_malloc(24); /* 2^64+1 can be represented in 21 chars + sign. */ + if ( str != 0 ) + sprintf(str,"%lld",(long long)item->valueint); + } + else + { + str = (char *)cJSON_malloc(66); /* This is a nice tradeoff. */ + if ( str != 0 ) + { + if ( fabs(floor(d) - d) <= DBL_EPSILON && fabs(d) < 1.0e60 ) + sprintf(str,"%.0f",d); + //else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d); + else + sprintf(str,"%.8f",d); + } + } + return str; +} + +static unsigned parse_hex4(const char *str) +{ + unsigned h=0; + if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; + h=h<<4;str++; + if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; + h=h<<4;str++; + if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; + h=h<<4;str++; + if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; + return h; +} + +/* Parse the input text into an unescaped cstring, and populate item. */ +static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; +static const char *parse_string(cJSON *item,const char *str) +{ + const char *ptr=str+1;char *ptr2;char *out;int32_t len=0;unsigned uc,uc2; + if (*str!='\"') {ep=str;return 0;} /* not a string! */ + + while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; // Skip escaped quotes + + out=(char*)cJSON_malloc(len+2); /* This is how long we need for the string, roughly. */ + if (!out) return 0; + + ptr=str+1;ptr2=out; + while (*ptr!='\"' && *ptr) + { + if (*ptr!='\\') + { + if ( *ptr == '%' && is_hexstr((char *)&ptr[1],2) && isprint(_decode_hex((char *)&ptr[1])) != 0 ) + *ptr2++ = _decode_hex((char *)&ptr[1]), ptr += 3; + else *ptr2++ = *ptr++; + } + else + { + ptr++; + switch (*ptr) + { + case 'b': *ptr2++='\b'; break; + case 'f': *ptr2++='\f'; break; + case 'n': *ptr2++='\n'; break; + case 'r': *ptr2++='\r'; break; + case 't': *ptr2++='\t'; break; + case 'u': // transcode utf16 to utf8 + uc=parse_hex4(ptr+1);ptr+=4; // get the unicode char + + if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid + + if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs + { + if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate. + uc2=parse_hex4(ptr+3);ptr+=6; + if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate + uc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF)); + } + + len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len; + + switch (len) { + case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; + case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; + case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; + case 1: *--ptr2 =(uc | firstByteMark[len]); + } + ptr2+=len; + break; + default: *ptr2++=*ptr; break; + } + ptr++; + } + } + *ptr2=0; + if (*ptr=='\"') ptr++; + item->valuestring=out; + item->type=cJSON_String; + return ptr; +} + +/* Render the cstring provided to an escaped version that can be printed. */ +static char *print_string_ptr(const char *str) +{ + const char *ptr;char *ptr2,*out;int32_t len=0;unsigned char token; + + if (!str) return cJSON_strdup(""); + ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;} + + out=(char*)cJSON_malloc(len+3+1); + if (!out) return 0; + + ptr2=out;ptr=str; + *ptr2++='\"'; + while (*ptr) + { + if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++; + else + { + *ptr2++='\\'; + switch (token=*ptr++) + { + case '\\': *ptr2++='\\'; break; + case '\"': *ptr2++='\"'; break; + case '\b': *ptr2++='b'; break; + case '\f': *ptr2++='f'; break; + case '\n': *ptr2++='n'; break; + case '\r': *ptr2++='r'; break; + case '\t': *ptr2++='t'; break; + default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */ + } + } + } + *ptr2++='\"';*ptr2++=0; + return out; +} +/* Invote print_string_ptr (which is useful) on an item. */ +static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);} + +/* Predeclare these prototypes. */ +static const char *parse_value(cJSON *item,const char *value); +static char *print_value(cJSON *item,int32_t depth,int32_t fmt); +static const char *parse_array(cJSON *item,const char *value); +static char *print_array(cJSON *item,int32_t depth,int32_t fmt); +static const char *parse_object(cJSON *item,const char *value); +static char *print_object(cJSON *item,int32_t depth,int32_t fmt); + +/* Utility to jump whitespace and cr/lf */ +static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;} + +/* Parse an object - create a new root, and populate. */ +cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int32_t require_null_terminated) +{ + const char *end=0; + cJSON *c=cJSON_New_Item(); + ep=0; + if (!c) return 0; /* memory fail */ + + end=parse_value(c,skip(value)); + if (!end) {cJSON_Delete(c);return 0;} /* parse failure. ep is set. */ + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) {end=skip(end);if (*end) {cJSON_Delete(c);ep=end;return 0;}} + if (return_parse_end) *return_parse_end=end; + return c; +} +/* Default options for cJSON_Parse */ +cJSON *cJSON_Parse(const char *value) +{ + return(cJSON_ParseWithOpts(value,0,0)); +} + +/* Render a cJSON item/entity/structure to text. */ +char *cJSON_Print(cJSON *item) +{ + return(print_value(item,0,1)); +} +char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);} + +/* Parser core - when encountering text, process appropriately. */ +static const char *parse_value(cJSON *item,const char *value) +{ + if (!value) return 0; /* Fail on null. */ + if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; } + if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; } + if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; } + if (*value=='\"') { return parse_string(item,value); } + if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); } + if (*value=='[') { return parse_array(item,value); } + if (*value=='{') { return parse_object(item,value); } + + ep=value;return 0; /* failure. */ +} + +/* Render a value to text. */ +static char *print_value(cJSON *item,int32_t depth,int32_t fmt) +{ + char *out=0; + if (!item) return 0; + switch ((item->type)&255) + { + case cJSON_NULL: out=cJSON_strdup("null"); break; + case cJSON_False: out=cJSON_strdup("false");break; + case cJSON_True: out=cJSON_strdup("true"); break; + case cJSON_Number: out=print_number(item);break; + case cJSON_String: out=print_string(item);break; + case cJSON_Array: out=print_array(item,depth,fmt);break; + case cJSON_Object: out=print_object(item,depth,fmt);break; + } + return out; +} + +/* Build an array from input text. */ +static const char *parse_array(cJSON *item,const char *value) +{ + cJSON *child; + if (*value!='[') {ep=value;return 0;} /* not an array! */ + + item->type=cJSON_Array; + value=skip(value+1); + if (*value==']') return value+1; /* empty array. */ + + item->child=child=cJSON_New_Item(); + if (!item->child) return 0; /* memory fail */ + value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */ + if (!value) return 0; + + while (*value==',') + { + cJSON *new_item; + if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ + child->next=new_item;new_item->prev=child;child=new_item; + value=skip(parse_value(child,skip(value+1))); + if (!value) return 0; /* memory fail */ + } + + if (*value==']') return value+1; /* end of array */ + ep=value;return 0; /* malformed. */ +} + +/* Render an array to text */ +static char *print_array(cJSON *item,int32_t depth,int32_t fmt) +{ + char **entries; + char *out=0,*ptr,*ret;int32_t len=5; + cJSON *child=item->child; + int32_t numentries=0,i=0,fail=0; + + /* How many entries in the array? */ + while (child) numentries++,child=child->next; + /* Explicitly handle numentries==0 */ + if (!numentries) + { + out=(char*)cJSON_malloc(3+1); + if (out) strcpy(out,"[]"); + return out; + } + /* Allocate an array to hold the values for each */ + entries=(char**)cJSON_malloc((1+numentries)*sizeof(char*)); + if (!entries) return 0; + memset(entries,0,numentries*sizeof(char*)); + /* Retrieve all the results: */ + child=item->child; + while (child && !fail) + { + ret=print_value(child,depth+1,fmt); + entries[i++]=ret; + if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1; + child=child->next; + } + + /* If we didn't fail, try to malloc the output string */ + if (!fail) out=(char*)cJSON_malloc(len+1); + /* If that fails, we fail. */ + if (!out) fail=1; + + /* Handle failure. */ + if (fail) + { + for (i=0;itype=cJSON_Object; + value=skip(value+1); + if (*value=='}') return value+1; /* empty array. */ + + item->child=child=cJSON_New_Item(); + if (!item->child) return 0; + value=skip(parse_string(child,skip(value))); + if (!value) return 0; + child->string=child->valuestring;child->valuestring=0; + if (*value!=':') {ep=value;return 0;} /* fail! */ + value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ + if (!value) return 0; + + while (*value==',') + { + cJSON *new_item; + if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ + child->next=new_item;new_item->prev=child;child=new_item; + value=skip(parse_string(child,skip(value+1))); + if (!value) return 0; + child->string=child->valuestring;child->valuestring=0; + if (*value!=':') {ep=value;return 0;} /* fail! */ + value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ + if (!value) return 0; + } + + if (*value=='}') return value+1; /* end of array */ + ep=value;return 0; /* malformed. */ +} + +/* Render an object to text. */ +static char *print_object(cJSON *item,int32_t depth,int32_t fmt) +{ + char **entries=0,**names=0; + char *out=0,*ptr,*ret,*str;int32_t len=7,i=0,j; + cJSON *child=item->child,*firstchild; + int32_t numentries=0,fail=0; + // Count the number of entries + firstchild = child; + while ( child ) + { + numentries++; + child = child->next; + if ( child == firstchild ) + { + printf("cJSON infinite loop detected\n"); + break; + } + } + /* Explicitly handle empty object case */ + if (!numentries) + { + out=(char*)cJSON_malloc(fmt?depth+4+1:3+1); + if (!out) return 0; + ptr=out;*ptr++='{'; + if (fmt) {*ptr++='\n';for (i=0;ichild;depth++;if (fmt) len+=depth; + while ( child ) + { + names[i]=str=print_string_ptr(child->string); + entries[i++]=ret=print_value(child,depth,fmt); + if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1; + child=child->next; + if ( child == firstchild ) + break; + } + + /* Try to allocate the output string */ + if (!fail) out=(char*)cJSON_malloc(len+1); + if (!out) fail=1; + + /* Handle failure */ + if (fail) + { + for (i=0;ichild;int32_t i=0;while(c)i++,c=c->next;return i;} +cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;} +cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;} + +/* Utility for array list handling. */ +static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;} +/* Utility for handling references. */ +static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;} + +/* Add item to array/object. */ +void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}} +void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);} +void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));} +void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));} + +cJSON *cJSON_DetachItemFromArray(cJSON *array,int32_t which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0; + if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;} +void cJSON_DeleteItemFromArray(cJSON *array,int32_t which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));} +cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int32_t i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;} +void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));} + +/* Replace array/object items with new ones. */ +void cJSON_ReplaceItemInArray(cJSON *array,int32_t which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return; + newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem; + if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);} +void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int32_t i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}} + +/* Create basic types: */ +cJSON *cJSON_CreateNull(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;} +cJSON *cJSON_CreateTrue(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;} +cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;} +cJSON *cJSON_CreateBool(int32_t b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;} +cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int64_t)num;}return item;} +cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;} +cJSON *cJSON_CreateArray(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;} +cJSON *cJSON_CreateObject(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;} + +/* Create Arrays: */ +cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} +cJSON *cJSON_CreateFloatArray(float *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} +cJSON *cJSON_CreateDoubleArray(double *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} +cJSON *cJSON_CreateStringArray(char **strings,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} + +/* Duplication */ +cJSON *cJSON_Duplicate(cJSON *item,int32_t recurse) +{ + cJSON *newitem,*cptr,*nptr=0,*newchild; + /* Bail on bad ptr */ + if (!item) return 0; + /* Create new item */ + newitem=cJSON_New_Item(); + if (!newitem) return 0; + /* Copy over all vars */ + newitem->type=item->type&(~cJSON_IsReference),newitem->valueint=item->valueint,newitem->valuedouble=item->valuedouble; + if (item->valuestring) {newitem->valuestring=cJSON_strdup(item->valuestring); if (!newitem->valuestring) {cJSON_Delete(newitem);return 0;}} + if (item->string) {newitem->string=cJSON_strdup(item->string); if (!newitem->string) {cJSON_Delete(newitem);return 0;}} + /* If non-recursive, then we're done! */ + if (!recurse) return newitem; + /* Walk the ->next chain for the child. */ + cptr=item->child; + while (cptr) + { + newchild=cJSON_Duplicate(cptr,1); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) {cJSON_Delete(newitem);return 0;} + if (nptr) {nptr->next=newchild,newchild->prev=nptr;nptr=newchild;} /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + else {newitem->child=newchild;nptr=newchild;} /* Set newitem->child and move to it */ + cptr=cptr->next; + } + return newitem; +} + +void cJSON_Minify(char *json) +{ + char *into=json; + while (*json) + { + if (*json==' ') json++; + else if (*json=='\t') json++; // Whitespace characters. + else if (*json=='\r') json++; + else if (*json=='\n') json++; + else if (*json=='/' && json[1]=='/') while (*json && *json!='\n') json++; // double-slash comments, to end of line. + else if (*json=='/' && json[1]=='*') {while (*json && !(*json=='*' && json[1]=='/')) json++;json+=2;} // multiline comments. + else if (*json=='\"'){*into++=*json++;while (*json && *json!='\"'){if (*json=='\\') *into++=*json++;*into++=*json++;}*into++=*json++;} // string literals, which are \" sensitive. + else *into++=*json++; // All other characters. + } + *into=0; // and null-terminate. +} + +// the following written by jl777 +/****************************************************************************** + * Copyright © 2014-2016 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. * + * * + ******************************************************************************/ + +void copy_cJSON(struct destbuf *dest,cJSON *obj) +{ + char *str; + int i; + long offset; + dest->buf[0] = 0; + if ( obj != 0 ) + { + str = cJSON_Print(obj); + if ( str != 0 ) + { + offset = stripquotes(str); + //strcpy(dest,str+offset); + for (i=0; ibuf[i]= str[offset+i]) == 0 ) + break; + dest->buf[i] = 0; + free(str); + } + } +} + +void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj) +{ + struct destbuf tmp; + maxlen--; + dest[0] = 0; + if ( maxlen > sizeof(tmp.buf) ) + maxlen = sizeof(tmp.buf); + copy_cJSON(&tmp,obj); + if ( strlen(tmp.buf) < maxlen ) + strcpy(dest,tmp.buf); + else dest[0] = 0; +} + +int64_t _get_cJSON_int(cJSON *json) +{ + struct destbuf tmp; + if ( json != 0 ) + { + copy_cJSON(&tmp,json); + if ( tmp.buf[0] != 0 ) + return(calc_nxt64bits(tmp.buf)); + } + return(0); +} + +int64_t get_cJSON_int(cJSON *json,char *field) +{ + cJSON *numjson; + if ( json != 0 ) + { + numjson = cJSON_GetObjectItem(json,field); + if ( numjson != 0 ) + return(_get_cJSON_int(numjson)); + } + return(0); +} + +int64_t _conv_cJSON_float(cJSON *json) +{ + int64_t conv_floatstr(char *); + struct destbuf tmp; + if ( json != 0 ) + { + copy_cJSON(&tmp,json); + return(conv_floatstr(tmp.buf)); + } + return(0); +} + +int64_t conv_cJSON_float(cJSON *json,char *field) +{ + if ( json != 0 ) + return(_conv_cJSON_float(cJSON_GetObjectItem(json,field))); + return(0); +} + +int32_t extract_cJSON_str(char *dest,int32_t max,cJSON *json,char *field) +{ + int32_t safecopy(char *dest,char *src,long len); + char *str; + cJSON *obj; + int32_t len; + long offset; + dest[0] = 0; + obj = cJSON_GetObjectItem(json,field); + if ( obj != 0 ) + { + str = cJSON_Print(obj); + offset = stripquotes(str); + len = safecopy(dest,str+offset,max); + free(str); + return(len); + } + return(0); +} + +cJSON *gen_list_json(char **list) +{ + cJSON *array,*item; + array = cJSON_CreateArray(); + while ( list != 0 && *list != 0 && *list[0] != 0 ) + { + item = cJSON_CreateString(*list++); + cJSON_AddItemToArray(array,item); + } + return(array); +} + +uint64_t get_API_nxt64bits(cJSON *obj) +{ + uint64_t nxt64bits = 0; + struct destbuf tmp; + if ( obj != 0 ) + { + if ( is_cJSON_Number(obj) != 0 ) + return((uint64_t)obj->valuedouble); + copy_cJSON(&tmp,obj); + nxt64bits = calc_nxt64bits(tmp.buf); + } + return(nxt64bits); +} +uint64_t j64bits(cJSON *json,char *field) { if ( field == 0 ) return(get_API_nxt64bits(json)); return(get_API_nxt64bits(cJSON_GetObjectItem(json,field))); } +uint64_t j64bitsi(cJSON *json,int32_t i) { return(get_API_nxt64bits(cJSON_GetArrayItem(json,i))); } + +uint64_t get_satoshi_obj(cJSON *json,char *field) +{ + int32_t i,n; + uint64_t prev,satoshis,mult = 1; + struct destbuf numstr,checkstr; + cJSON *numjson; + numjson = cJSON_GetObjectItem(json,field); + copy_cJSON(&numstr,numjson); + satoshis = prev = 0; mult = 1; n = (int32_t)strlen(numstr.buf); + for (i=n-1; i>=0; i--,mult*=10) + { + satoshis += (mult * (numstr.buf[i] - '0')); + if ( satoshis < prev ) + printf("get_satoshi_obj numstr.(%s) i.%d prev.%llu vs satoshis.%llu\n",numstr.buf,i,(unsigned long long)prev,(unsigned long long)satoshis); + prev = satoshis; + } + sprintf(checkstr.buf,"%llu",(long long)satoshis); + if ( strcmp(checkstr.buf,numstr.buf) != 0 ) + { + printf("SATOSHI GREMLIN?? numstr.(%s) -> %.8f -> (%s)\n",numstr.buf,dstr(satoshis),checkstr.buf); + } + return(satoshis); +} + +void add_satoshis_json(cJSON *json,char *field,uint64_t satoshis) +{ + cJSON *obj; + char numstr[64]; + sprintf(numstr,"%lld",(long long)satoshis); + obj = cJSON_CreateString(numstr); + cJSON_AddItemToObject(json,field,obj); + if ( satoshis != get_satoshi_obj(json,field) ) + printf("error adding satoshi obj %ld -> %ld\n",(unsigned long)satoshis,(unsigned long)get_satoshi_obj(json,field)); +} + +char *cJSON_str(cJSON *json) +{ + if ( json != 0 && is_cJSON_String(json) != 0 ) + return(json->valuestring); + return(0); +} + +void jadd(cJSON *json,char *field,cJSON *item) { if ( json != 0 )cJSON_AddItemToObject(json,field,item); } +void jaddstr(cJSON *json,char *field,char *str) { if ( json != 0 && str != 0 ) cJSON_AddItemToObject(json,field,cJSON_CreateString(str)); } +void jaddnum(cJSON *json,char *field,double num) { if ( json != 0 )cJSON_AddItemToObject(json,field,cJSON_CreateNumber(num)); } +void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddstr(json,field,numstr); } +void jaddi(cJSON *json,cJSON *item) { if ( json != 0 ) cJSON_AddItemToArray(json,item); } +void jaddistr(cJSON *json,char *str) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateString(str)); } +void jaddinum(cJSON *json,double num) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateNumber(num)); } +void jaddi64bits(cJSON *json,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddistr(json,numstr); } +char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(cJSON_str(json)); return(cJSON_str(cJSON_GetObjectItem(json,field))); } + +char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } +char *jprint(cJSON *json,int32_t freeflag) +{ + char *str; + /*static portable_mutex_t mutex; static int32_t initflag; + if ( initflag == 0 ) + { + portable_mutex_init(&mutex); + initflag = 1; + }*/ + if ( json == 0 ) + return(clonestr("{}")); + //portable_mutex_lock(&mutex); + //usleep(5000); + str = cJSON_Print(json), _stripwhite(str,' '); + if ( freeflag != 0 ) + free_json(json); + //portable_mutex_unlock(&mutex); + return(str); +} + +bits256 get_API_bits256(cJSON *obj) +{ + bits256 hash; char *str; + memset(hash.bytes,0,sizeof(hash)); + if ( obj != 0 ) + { + if ( is_cJSON_String(obj) != 0 && (str= obj->valuestring) != 0 && strlen(str) == 64 ) + decode_hex(hash.bytes,sizeof(hash),str); + } + return(hash); +} +bits256 jbits256(cJSON *json,char *field) { if ( field == 0 ) return(get_API_bits256(json)); return(get_API_bits256(cJSON_GetObjectItem(json,field))); } +bits256 jbits256i(cJSON *json,int32_t i) { return(get_API_bits256(cJSON_GetArrayItem(json,i))); } +void jaddbits256(cJSON *json,char *field,bits256 hash) { char str[65]; bits256_str(str,hash), jaddstr(json,field,str); } +void jaddibits256(cJSON *json,bits256 hash) { char str[65]; bits256_str(str,hash), jaddistr(json,str); } + +char *get_cJSON_fieldname(cJSON *obj) +{ + if ( obj != 0 ) + { + if ( obj->child != 0 && obj->child->string != 0 ) + return(obj->child->string); + else if ( obj->string != 0 ) + return(obj->string); + } + return((char *)""); +} + +int32_t jnum(cJSON *obj,char *field) +{ + char *str; int32_t polarity = 1; + if ( field != 0 ) + obj = jobj(obj,field); + if ( obj != 0 ) + { + if ( is_cJSON_Number(obj) != 0 ) + return(obj->valuedouble); + else if ( is_cJSON_String(obj) != 0 && (str= jstr(obj,0)) != 0 ) + { + if ( str[0] == '-' ) + polarity = -1, str++; + return(polarity * (int32_t)calc_nxt64bits(str)); + } + } + return(0); +} + +void ensure_jsonitem(cJSON *json,char *field,char *value) +{ + cJSON *obj = cJSON_GetObjectItem(json,field); + if ( obj == 0 ) + cJSON_AddItemToObject(json,field,cJSON_CreateString(value)); + else cJSON_ReplaceItemInObject(json,field,cJSON_CreateString(value)); +} + +int32_t in_jsonarray(cJSON *array,char *value) +{ + int32_t i,n; + struct destbuf remote; + if ( array != 0 && is_cJSON_Array(array) != 0 ) + { + n = cJSON_GetArraySize(array); + for (i=0; i= range ) + x = (range - 1); + return((int32_t)x); +} + +int32_t get_API_int(cJSON *obj,int32_t val) +{ + struct destbuf buf; + if ( obj != 0 ) + { + if ( is_cJSON_Number(obj) != 0 ) + return((int32_t)obj->valuedouble); + copy_cJSON(&buf,obj); + val = myatoi(buf.buf,0); + if ( val < 0 ) + val = 0; + } + return(val); +} +int32_t jint(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(get_API_int(json,0)); return(get_API_int(cJSON_GetObjectItem(json,field),0)); } +int32_t jinti(cJSON *json,int32_t i) { if ( json == 0 ) return(0); return(get_API_int(cJSON_GetArrayItem(json,i),0)); } + +uint32_t get_API_uint(cJSON *obj,uint32_t val) +{ + struct destbuf buf; + if ( obj != 0 ) + { + if ( is_cJSON_Number(obj) != 0 ) + return((uint32_t)obj->valuedouble); + copy_cJSON(&buf,obj); + val = myatoi(buf.buf,0); + } + return(val); +} +uint32_t juint(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(get_API_uint(json,0)); return(get_API_uint(cJSON_GetObjectItem(json,field),0)); } +uint32_t juinti(cJSON *json,int32_t i) { if ( json == 0 ) return(0); return(get_API_uint(cJSON_GetArrayItem(json,i),0)); } + +double get_API_float(cJSON *obj) +{ + double val = 0.; + struct destbuf buf; + if ( obj != 0 ) + { + if ( is_cJSON_Number(obj) != 0 ) + return(obj->valuedouble); + copy_cJSON(&buf,obj); + val = atof(buf.buf); + } + return(val); +} + +double jdouble(cJSON *json,char *field) +{ + if ( json != 0 ) + { + if ( field == 0 ) + return(get_API_float(json)); + else return(get_API_float(cJSON_GetObjectItem(json,field))); + } else return(0.); +} + +double jdoublei(cJSON *json,int32_t i) +{ + if ( json != 0 ) + return(get_API_float(cJSON_GetArrayItem(json,i))); + else return(0.); +} + +cJSON *jobj(cJSON *json,char *field) { if ( json != 0 ) return(cJSON_GetObjectItem(json,field)); return(0); } + +void jdelete(cJSON *json,char *field) +{ + if ( jobj(json,field) != 0 ) + cJSON_DeleteItemFromObject(json,field); +} + +cJSON *jduplicate(cJSON *json) { return(cJSON_Duplicate(json,1)); } + +cJSON *jitem(cJSON *array,int32_t i) { if ( array != 0 && is_cJSON_Array(array) != 0 && cJSON_GetArraySize(array) > i ) return(cJSON_GetArrayItem(array,i)); return(0); } +cJSON *jarray(int32_t *nump,cJSON *json,char *field) +{ + cJSON *array; + if ( json != 0 ) + { + if ( field == 0 ) + array = json; + else array = cJSON_GetObjectItem(json,field); + if ( array != 0 && is_cJSON_Array(array) != 0 && (*nump= cJSON_GetArraySize(array)) > 0 ) + return(array); + } + *nump = 0; + return(0); +} + +int32_t expand_nxt64bits(char *NXTaddr,uint64_t nxt64bits) +{ + int32_t i,n; + uint64_t modval; + char rev[64]; + for (i=0; nxt64bits!=0; i++) + { + modval = nxt64bits % 10; + rev[i] = (char)(modval + '0'); + nxt64bits /= 10; + } + n = i; + for (i=0; i= 22 ) + { + printf("calc_nxt64bits: illegal NXTaddr.(%s) too long\n",NXTaddr); + return(0); + } + else if ( strcmp(NXTaddr,"0") == 0 || strcmp(NXTaddr,"false") == 0 ) + { + // printf("zero address?\n"); getchar(); + return(0); + } + if ( NXTaddr[0] == '-' ) + polarity = -1, NXTaddr++, n--; + mult = 1; + lastval = 0; + for (i=n-1; i>=0; i--,mult*=10) + { + c = NXTaddr[i]; + if ( c < '0' || c > '9' ) + { + printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i); +#ifdef __APPLE__ + //while ( 1 ) + { + //sleep(60); + printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i); + } +#endif + return(0); + } + nxt64bits += mult * (c - '0'); + if ( nxt64bits < lastval ) + printf("calc_nxt64bits: warning: 64bit overflow %llx < %llx\n",(long long)nxt64bits,(long long)lastval); + lastval = nxt64bits; + } + while ( *NXTaddr == '0' && *NXTaddr != 0 ) + NXTaddr++; + if ( cmp_nxt64bits(NXTaddr,nxt64bits) != 0 ) + printf("error calculating nxt64bits: %s -> %llx -> %s\n",NXTaddr,(long long)nxt64bits,nxt64str(nxt64bits)); + if ( polarity < 0 ) + return(-(int64_t)nxt64bits); + return(nxt64bits); +} + +cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num) +{ + int32_t j; cJSON *array; + array = cJSON_CreateArray(); + for (j=0; j +#include +#include +#include +#include +#include +#include + +#include "../crypto777/OS_portable.h" + +#define SATOSHIDEN ((uint64_t)100000000L) +#define dstr(x) ((double)(x) / SATOSHIDEN) +#define MAX_JSON_FIELD 4096 // on the big side + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* cJSON Types: */ +#define cJSON_False 0 +#define cJSON_True 1 +#define cJSON_NULL 2 +#define cJSON_Number 3 +#define cJSON_String 4 +#define cJSON_Array 5 +#define cJSON_Object 6 + +#define is_cJSON_Null(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_NULL) +#define is_cJSON_Array(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Array) +#define is_cJSON_String(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_String) +#define is_cJSON_Number(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Number) +#define is_cJSON_Object(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Object) +#define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True) +#define is_cJSON_False(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_False) + +#define cJSON_IsReference 256 + + /* The cJSON structure: */ + typedef struct cJSON { + struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + + int32_t type; /* The type of the item, as above. */ + + char *valuestring; /* The item's string, if type==cJSON_String */ + int64_t valueint; /* The item's number, if type==cJSON_Number */ + double valuedouble; /* The item's number, if type==cJSON_Number */ + + char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + } cJSON; + + typedef struct cJSON_Hooks { + void *(*malloc_fn)(size_t sz); + void (*free_fn)(void *ptr); + } cJSON_Hooks; + + /* Supply malloc, realloc and free functions to cJSON */ + extern void cJSON_InitHooks(cJSON_Hooks* hooks); + + + /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ + extern cJSON *cJSON_Parse(const char *value); + /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ + extern char *cJSON_Print(cJSON *item); + /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ + extern char *cJSON_PrintUnformatted(cJSON *item); + /* Delete a cJSON entity and all subentities. */ + extern void cJSON_Delete(cJSON *c); + + /* Returns the number of items in an array (or object). */ + extern int cJSON_GetArraySize(cJSON *array); + /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ + extern cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item); + /* Get item "string" from object. Case insensitive. */ + extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string); + + /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ + extern const char *cJSON_GetErrorPtr(void); + + /* These calls create a cJSON item of the appropriate type. */ + extern cJSON *cJSON_CreateNull(void); + extern cJSON *cJSON_CreateTrue(void); + extern cJSON *cJSON_CreateFalse(void); + extern cJSON *cJSON_CreateBool(int32_t b); + extern cJSON *cJSON_CreateNumber(double num); + extern cJSON *cJSON_CreateString(const char *string); + extern cJSON *cJSON_CreateArray(void); + extern cJSON *cJSON_CreateObject(void); + + /* These utilities create an Array of count items. */ + extern cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count); + extern cJSON *cJSON_CreateFloatArray(float *numbers,int32_t count); + extern cJSON *cJSON_CreateDoubleArray(double *numbers,int32_t count); + extern cJSON *cJSON_CreateStringArray(char **strings,int32_t count); + + /* Append item to the specified array/object. */ + extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); + extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item); + /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ + extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); + extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item); + + /* Remove/Detatch items from Arrays/Objects. */ + extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int32_t which); + extern void cJSON_DeleteItemFromArray(cJSON *array,int32_t which); + extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string); + extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string); + + /* Update array items. */ + extern void cJSON_ReplaceItemInArray(cJSON *array,int32_t which,cJSON *newitem); + extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); + + /* Duplicate a cJSON item */ + extern cJSON *cJSON_Duplicate(cJSON *item,int32_t recurse); + /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will + need to be released. With recurse!=0, it will duplicate any children connected to the item. + The item->next and ->prev pointers are always zero on return from Duplicate. */ + + /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ + extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int32_t require_null_terminated); + + extern void cJSON_Minify(char *json); + + /* Macros for creating things quickly. */ +#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) +#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) +#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) +#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) +#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) +#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) + + struct destbuf { char buf[MAX_JSON_FIELD]; }; + + /* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val)) +#define jfieldstr get_cJSON_fieldname + + char *cJSON_str(cJSON *json); + char *jstr(cJSON *json,char *field); + char *jprint(cJSON *json,int32_t freeflag); + int32_t jint(cJSON *json,char *field); + uint32_t juint(cJSON *json,char *field); + char *jstri(cJSON *json,int32_t i); + int32_t jinti(cJSON *json,int32_t i); + uint32_t juinti(cJSON *json,int32_t i); + uint64_t j64bitsi(cJSON *json,int32_t i); + double jdoublei(cJSON *json,int32_t i); + double jdouble(cJSON *json,char *field); + cJSON *jobj(cJSON *json,char *field); + cJSON *jarray(int32_t *nump,cJSON *json,char *field); + cJSON *jitem(cJSON *array,int32_t i); + uint64_t j64bits(cJSON *json,char *field); + void jadd(cJSON *json,char *field,cJSON *item); + void jaddstr(cJSON *json,char *field,char *str); + void jaddnum(cJSON *json,char *field,double num); + void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits); + void jaddi(cJSON *json,cJSON *item); + void jaddistr(cJSON *json,char *str); + void jaddinum(cJSON *json,double num); + void jaddi64bits(cJSON *json,uint64_t nxt64bits); + void jdelete(cJSON *object,char *string); + cJSON *jduplicate(cJSON *json); + int32_t jnum(cJSON *obj,char *field); + + bits256 jbits256(cJSON *json,char *field); + bits256 jbits256i(cJSON *json,int32_t i); + void jaddbits256(cJSON *json,char *field,bits256 hash); + void jaddibits256(cJSON *json,bits256 hash); + void copy_cJSON(struct destbuf *dest,cJSON *obj); + void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj); + cJSON *gen_list_json(char **list); + int32_t extract_cJSON_str(char *dest,int32_t max,cJSON *json,char *field); + + void free_json(cJSON *json); + int64_t _conv_cJSON_float(cJSON *json); + int64_t conv_cJSON_float(cJSON *json,char *field); + int64_t get_cJSON_int(cJSON *json,char *field); + void add_satoshis_json(cJSON *json,char *field,uint64_t satoshis); + uint64_t get_satoshi_obj(cJSON *json,char *field); + + int32_t get_API_int(cJSON *obj,int32_t val); + uint32_t get_API_uint(cJSON *obj,uint32_t val); + uint64_t get_API_nxt64bits(cJSON *obj); + double get_API_float(cJSON *obj); + char *get_cJSON_fieldname(cJSON *obj); + void ensure_jsonitem(cJSON *json,char *field,char *value); + int32_t in_jsonarray(cJSON *array,char *value); + char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params); + uint64_t calc_nxt64bits(const char *str); + int32_t expand_nxt64bits(char *str,uint64_t nxt64bits); + char *nxt64str(uint64_t nxt64bits); + char *nxt64str2(uint64_t nxt64bits); + cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num); + int32_t myatoi(char *str,int32_t range); + + char *stringifyM(char *str); +#define replace_backslashquotes unstringify + char *unstringify(char *str); +#define jtrue cJSON_CreateTrue +#define jfalse cJSON_CreateFalse + +#define jfieldname get_cJSON_fieldname + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 9e6e626a9..d8d742eb8 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -18,6 +18,7 @@ typedef union _bits256 bits256; #include "mini-gmp.c" #include "uthash.h" +#include "cJSON.h" #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" From c23b9ce30f494a3ca40ececdb2b47b06e9672b40 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:07:26 -0300 Subject: [PATCH 044/205] test --- src/cJSON.c | 2 +- src/cJSON.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cJSON.c b/src/cJSON.c index 5035f9a9b..ce323fb69 100755 --- a/src/cJSON.c +++ b/src/cJSON.c @@ -25,7 +25,7 @@ /* JSON parser in C. */ #include -#include "../includes/cJSON.h" +#include "cJSON.h" #ifndef DBL_EPSILON #define DBL_EPSILON 2.2204460492503131E-16 diff --git a/src/cJSON.h b/src/cJSON.h index b75e73bf1..483b3055d 100755 --- a/src/cJSON.h +++ b/src/cJSON.h @@ -31,7 +31,7 @@ #include #include -#include "../crypto777/OS_portable.h" +//#include "../crypto777/OS_portable.h" #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) From 14871d491a747baf2e2ff321ea4fcfdc934b5d0c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:08:44 -0300 Subject: [PATCH 045/205] test --- src/cJSON.h | 2 +- src/komodo_bitcoind.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cJSON.h b/src/cJSON.h index 483b3055d..c14a72130 100755 --- a/src/cJSON.h +++ b/src/cJSON.h @@ -34,7 +34,7 @@ //#include "../crypto777/OS_portable.h" #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)(x) / SATOSHIDEN) +//#define dstr(x) ((double)(x) / SATOSHIDEN) #define MAX_JSON_FIELD 4096 // on the big side #ifdef __cplusplus diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fbebb0255..41805025c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -302,7 +302,7 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port) sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); //printf("postdata.(%s) USERPASS.(%s)\n",postdata,USERPASS); - retstr2 = bitcoind_RPC(&retstr,"debug",url,USERPASS,method,params); + retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,USERPASS,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } return(retstr); From 62e097708d79a5a4858331635c0006cee6e85467 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:12:05 -0300 Subject: [PATCH 046/205] test --- src/komodo_utils.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d8d742eb8..e1b0fd223 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1015,3 +1015,12 @@ void komodo_configfile(char *symbol,uint16_t port) } else printf("couldnt open.(%s)\n",fname); } } + +double OS_milliseconds() +{ + struct timeval tv; double millis; + gettimeofday(&tv,NULL); + millis = ((double)tv.tv_sec * 1000. + (double)tv.tv_usec / 1000.); + //printf("tv_sec.%ld usec.%d %f\n",tv.tv_sec,tv.tv_usec,millis); + return(millis); +} \ No newline at end of file From 4ec67e744a81921b8ddbfae7f9fc459699de5d7d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:14:34 -0300 Subject: [PATCH 047/205] test --- src/komodo_bitcoind.h | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 41805025c..9f3b1b510 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -32,9 +32,44 @@ struct return_string { char *ptr; size_t len; }; #define CURL_GLOBAL_WIN32 (1<<1) -size_t accumulate(void *ptr, size_t size, size_t nmemb, struct return_string *s); -void init_string(struct return_string *s); +/************************************************************************ + * + * Initialize the string handler so that it is thread safe + * + ************************************************************************/ +void init_string(struct return_string *s) +{ + s->len = 0; + s->ptr = (char *)calloc(1,s->len+1); + if ( s->ptr == NULL ) + { + fprintf(stderr,"init_string malloc() failed\n"); + exit(-1); + } + s->ptr[0] = '\0'; +} + +/************************************************************************ + * + * Use the "writer" to accumulate text until done + * + ************************************************************************/ + +size_t accumulatebytes(void *ptr,size_t size,size_t nmemb,struct return_string *s) +{ + size_t new_len = s->len + size*nmemb; + s->ptr = (char *)realloc(s->ptr,new_len+1); + if ( s->ptr == NULL ) + { + fprintf(stderr, "accumulate realloc() failed\n"); + exit(-1); + } + memcpy(s->ptr+s->len,ptr,size*nmemb); + s->ptr[new_len] = '\0'; + s->len = new_len; + return(size * nmemb); +} /************************************************************************ * @@ -132,7 +167,7 @@ try_again: curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_URL, url); - curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulate); // send all data to this function + curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulatebytes); // send all data to this function curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback From 1c1d7e2690e026b3492acb935d6239beaf33168c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:16:20 -0300 Subject: [PATCH 048/205] 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 e1b0fd223..2a0ce41ec 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -18,7 +18,7 @@ typedef union _bits256 bits256; #include "mini-gmp.c" #include "uthash.h" -#include "cJSON.h" +#include "cJSON.c" #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" From 8d6bd385ca416f9545c52febbdb0f73e9809cca8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:17:25 -0300 Subject: [PATCH 049/205] test --- src/komodo.h | 1 + src/komodo_utils.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index abf999069..efa098e6f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -34,6 +34,7 @@ pthread_mutex_t komodo_mutex; char USERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "komodo_utils.h" +#include "cJSON.c" #include "komodo_bitcoind.h" #include "komodo_interest.h" #ifdef KOMODO_PAX diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2a0ce41ec..30507e42f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -18,7 +18,6 @@ typedef union _bits256 bits256; #include "mini-gmp.c" #include "uthash.h" -#include "cJSON.c" #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" From 32b1b4433d031bb647f4a9ed97f89ebc4b41c61e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:20:55 -0300 Subject: [PATCH 050/205] test --- src/cJSON.h | 1 - src/komodo_utils.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/cJSON.h b/src/cJSON.h index c14a72130..6d85f6fa7 100755 --- a/src/cJSON.h +++ b/src/cJSON.h @@ -34,7 +34,6 @@ //#include "../crypto777/OS_portable.h" #define SATOSHIDEN ((uint64_t)100000000L) -//#define dstr(x) ((double)(x) / SATOSHIDEN) #define MAX_JSON_FIELD 4096 // on the big side #ifdef __cplusplus diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 30507e42f..5842c4d53 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#define dstr(x) ((double)(x) / SATOSHIDEN) + union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; typedef union _bits256 bits256; @@ -832,6 +834,41 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex) return(n + adjust); } +char hexbyte(int32_t c) +{ + c &= 0xf; + if ( c < 10 ) + return('0'+c); + else if ( c < 16 ) + return('a'+c-10); + else return(0); +} + +int32_t init_hexbytes_noT(char *hexbytes,unsigned char *message,long len) +{ + int32_t i; + if ( len <= 0 ) + { + hexbytes[0] = 0; + return(1); + } + for (i=0; i>4) & 0xf); + hexbytes[i*2 + 1] = hexbyte(message[i] & 0xf); + //printf("i.%d (%02x) [%c%c]\n",i,message[i],hexbytes[i*2],hexbytes[i*2+1]); + } + hexbytes[len*2] = 0; + //printf("len.%ld\n",len*2+1); + return((int32_t)len*2+1); +} + +char *bits256_str(char hexstr[65],bits256 x) +{ + init_hexbytes_noT(hexstr,x.bytes,sizeof(x)); + return(hexstr); +} + int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp) { int32_t i; uint64_t x; From c2576b86792931238baa2421d0e9a5d0dd5188e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:22:34 -0300 Subject: [PATCH 051/205] test --- src/cJSON.h | 1 - src/komodo_interest.h | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cJSON.h b/src/cJSON.h index 6d85f6fa7..d3076aa53 100755 --- a/src/cJSON.h +++ b/src/cJSON.h @@ -33,7 +33,6 @@ //#include "../crypto777/OS_portable.h" -#define SATOSHIDEN ((uint64_t)100000000L) #define MAX_JSON_FIELD 4096 // on the big side #ifdef __cplusplus diff --git a/src/komodo_interest.h b/src/komodo_interest.h index b71178d15..cfcc3ed83 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -14,7 +14,8 @@ ******************************************************************************/ #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% -#define dstr(x) ((double)(x)/COIN) +#define dstr(x) ((double)(x)/SATOSHIDEN) +#define SATOSHIDEN ((uint64_t)100000000L) uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest) { From 562c328f5b79784dfa14a0fd149207fecccbc87d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:23:39 -0300 Subject: [PATCH 052/205] test --- src/komodo_interest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index cfcc3ed83..bcac9e588 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -14,7 +14,7 @@ ******************************************************************************/ #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% -#define dstr(x) ((double)(x)/SATOSHIDEN) +#define dstr(x) ((double)(x) / SATOSHIDEN) #define SATOSHIDEN ((uint64_t)100000000L) uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest) From 453e1052c2d0ed4a0006770fc455406209e545f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:24:46 -0300 Subject: [PATCH 053/205] test --- src/komodo_interest.h | 2 -- src/komodo_utils.h | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index bcac9e588..68ab2e2f3 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -14,8 +14,6 @@ ******************************************************************************/ #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% -#define dstr(x) ((double)(x) / SATOSHIDEN) -#define SATOSHIDEN ((uint64_t)100000000L) uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 5842c4d53..72aad92a3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -13,6 +13,7 @@ * * ******************************************************************************/ +#define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; From 34c42c40ebb4124ad49725697d793224148195d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:26:09 -0300 Subject: [PATCH 054/205] test --- src/cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cJSON.c b/src/cJSON.c index ce323fb69..02a5c91c7 100755 --- a/src/cJSON.c +++ b/src/cJSON.c @@ -837,7 +837,7 @@ char *jprint(cJSON *json,int32_t freeflag) initflag = 1; }*/ if ( json == 0 ) - return(clonestr("{}")); + return(clonestr((char *)"{}")); //portable_mutex_lock(&mutex); //usleep(5000); str = cJSON_Print(json), _stripwhite(str,' '); From f3d5295c6d4914a0b5028bbec8848c15d884775c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:28:49 -0300 Subject: [PATCH 055/205] test --- src/cJSON.c | 8 ++++++++ src/komodo_utils.h | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/cJSON.c b/src/cJSON.c index 02a5c91c7..43aec68bf 100755 --- a/src/cJSON.c +++ b/src/cJSON.c @@ -707,6 +707,14 @@ int64_t get_cJSON_int(cJSON *json,char *field) return(0); } +int64_t conv_floatstr(char *numstr) +{ + double val,corr; + val = atof(numstr); + corr = (val < 0.) ? -0.50000000001 : 0.50000000001; + return((int64_t)(val * SATOSHIDEN + corr)); +} + int64_t _conv_cJSON_float(cJSON *json) { int64_t conv_floatstr(char *); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 72aad92a3..2ce3a295a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -976,6 +976,28 @@ char *clonestr(char *str) return(clone); } +int32_t safecopy(char *dest,char *src,long len) +{ + int32_t i = -1; + if ( src != 0 && dest != 0 && src != dest ) + { + if ( dest != 0 ) + memset(dest,0,len); + for (i=0; i Date: Tue, 25 Oct 2016 19:31:24 -0300 Subject: [PATCH 056/205] test --- 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 9f3b1b510..e9d416efb 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -340,7 +340,7 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port) retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,USERPASS,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } - return(retstr); + return(retstr2); } //curl --url "http://127.0.0.1:13033" --user "user1557335368:pass111720054" --data "{\"method\":\"getinfo\",\"params\":[]}" From 4ac6cd922b1561998be10497e4882dc92646634f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:35:33 -0300 Subject: [PATCH 057/205] test --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9d416efb..c55b2901c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -329,7 +329,8 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * char *komodo_issuemethod(char *method,char *params,uint16_t port) { - static void *cHandle; char url[512],*retstr=0,*retstr2,postdata[8192]; + //static void *cHandle; + char url[512],*retstr=0,*retstr2,postdata[8192]; if ( params == 0 || params[0] == 0 ) params = (char *)"[]"; if ( strlen(params) < sizeof(postdata)-128 ) From a9132082564eda08f6375d804101cfa25b2b922f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:35:55 -0300 Subject: [PATCH 058/205] test --- 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 c55b2901c..33e23c9fc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -330,7 +330,7 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * char *komodo_issuemethod(char *method,char *params,uint16_t port) { //static void *cHandle; - char url[512],*retstr=0,*retstr2,postdata[8192]; + char url[512],*retstr=0,*retstr2=0,postdata[8192]; if ( params == 0 || params[0] == 0 ) params = (char *)"[]"; if ( strlen(params) < sizeof(postdata)-128 ) From c42b46db1aa5918df9ae974d37eb8cbc41e2a3a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:47:58 -0300 Subject: [PATCH 059/205] test --- src/komodo_gateway.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2c61bbd0f..9c42772f9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -13,6 +13,23 @@ * * ******************************************************************************/ +void komodo_gateway_iteration() +{ + char *retstr; uint32_t n=0; static uint32_t r,counter=0; + if ( r == 0 ) + r = rand(); + if ( (counter++ % 10) == (r % 10) ) + { + printf("%s calling getinfo %d\n",ASSETCHAINS_SYMBOL,n); + if ( (retstr= komodo_issuemethod((char *)"getinfo",0,7771)) != 0 ) + { + //printf("GETINFO from.%s (%s)\n",ASSETCHAINS_SYMBOL,retstr); + free(retstr); + n++; + } else printf("error from %s\n",ASSETCHAINS_SYMBOL); + } +} + void komodo_gateway_issuer() // "assetchain" { From 30f61477ac04599263a7b8b44c899729f0ca4cbc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:49:52 -0300 Subject: [PATCH 060/205] test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9c42772f9..f5d3c82ca 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -13,20 +13,20 @@ * * ******************************************************************************/ -void komodo_gateway_iteration() +void komodo_gateway_iteration(char *symbol) { char *retstr; uint32_t n=0; static uint32_t r,counter=0; if ( r == 0 ) r = rand(); if ( (counter++ % 10) == (r % 10) ) { - printf("%s calling getinfo %d\n",ASSETCHAINS_SYMBOL,n); + printf("%s calling getinfo %d\n",symbol,n); if ( (retstr= komodo_issuemethod((char *)"getinfo",0,7771)) != 0 ) { //printf("GETINFO from.%s (%s)\n",ASSETCHAINS_SYMBOL,retstr); free(retstr); n++; - } else printf("error from %s\n",ASSETCHAINS_SYMBOL); + } else printf("error from %s\n",symbol); } } From a4cbda932cc0edf299657caafc5b13cf7dcca0eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:54:41 -0300 Subject: [PATCH 061/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f5d3c82ca..b5a2879dc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -15,7 +15,7 @@ void komodo_gateway_iteration(char *symbol) { - char *retstr; uint32_t n=0; static uint32_t r,counter=0; + char *retstr; static uint32_t r,n,counter=0; if ( r == 0 ) r = rand(); if ( (counter++ % 10) == (r % 10) ) From 2c6bdd83ed4c5257a6beab5cfe5bdb8c605a5613 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 19:59:34 -0300 Subject: [PATCH 062/205] test --- src/komodo_gateway.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b5a2879dc..c95ccf006 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -15,7 +15,7 @@ void komodo_gateway_iteration(char *symbol) { - char *retstr; static uint32_t r,n,counter=0; + char *retstr; int32_t i,num; cJSON *item,*listobj; static uint32_t r,n,counter=0; if ( r == 0 ) r = rand(); if ( (counter++ % 10) == (r % 10) ) @@ -25,6 +25,23 @@ void komodo_gateway_iteration(char *symbol) { //printf("GETINFO from.%s (%s)\n",ASSETCHAINS_SYMBOL,retstr); free(retstr); + if ( (retstr= komodo_issuemethod((char *)"listtransactions",0,7771)) != 0 ) + { + //printf("LIST.(%s)\n",retstr); + if ( (listobj= cJSON_Parse(retstr)) != 0 ) + { + if ( (num= cJSON_GetArraySize(listobj)) > 0 ) + { + for (i=0; i Date: Tue, 25 Oct 2016 20:03:05 -0300 Subject: [PATCH 063/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c95ccf006..765010375 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -27,7 +27,7 @@ void komodo_gateway_iteration(char *symbol) free(retstr); if ( (retstr= komodo_issuemethod((char *)"listtransactions",0,7771)) != 0 ) { - //printf("LIST.(%s)\n",retstr); + printf("LIST.(%s)\n",retstr); if ( (listobj= cJSON_Parse(retstr)) != 0 ) { if ( (num= cJSON_GetArraySize(listobj)) > 0 ) @@ -35,7 +35,7 @@ void komodo_gateway_iteration(char *symbol) for (i=0; i Date: Tue, 25 Oct 2016 20:05:55 -0300 Subject: [PATCH 064/205] test --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 765010375..866d2d859 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -15,7 +15,7 @@ void komodo_gateway_iteration(char *symbol) { - char *retstr; int32_t i,num; cJSON *item,*listobj; static uint32_t r,n,counter=0; + char *retstr; int32_t i,num; cJSON *item,*array,*listobj; static uint32_t r,n,counter=0; if ( r == 0 ) r = rand(); if ( (counter++ % 10) == (r % 10) ) @@ -27,14 +27,14 @@ void komodo_gateway_iteration(char *symbol) free(retstr); if ( (retstr= komodo_issuemethod((char *)"listtransactions",0,7771)) != 0 ) { - printf("LIST.(%s)\n",retstr); + //printf("LIST.(%s)\n",retstr); if ( (listobj= cJSON_Parse(retstr)) != 0 ) { - if ( (num= cJSON_GetArraySize(listobj)) > 0 ) + if ( (array= jarray(&num,listobj,"result")) > 0 ) { for (i=0; i Date: Tue, 25 Oct 2016 20:07:19 -0300 Subject: [PATCH 065/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 866d2d859..e110a5386 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -30,7 +30,7 @@ void komodo_gateway_iteration(char *symbol) //printf("LIST.(%s)\n",retstr); if ( (listobj= cJSON_Parse(retstr)) != 0 ) { - if ( (array= jarray(&num,listobj,"result")) > 0 ) + if ( (array= jarray(&num,listobj,"result")) != 0 ) { for (i=0; i Date: Tue, 25 Oct 2016 20:08:15 -0300 Subject: [PATCH 066/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e110a5386..2e93af1dd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -30,7 +30,7 @@ void komodo_gateway_iteration(char *symbol) //printf("LIST.(%s)\n",retstr); if ( (listobj= cJSON_Parse(retstr)) != 0 ) { - if ( (array= jarray(&num,listobj,"result")) != 0 ) + if ( (array= jarray(&num,listobj,(char *)"result")) != 0 ) { for (i=0; i Date: Tue, 25 Oct 2016 20:11:59 -0300 Subject: [PATCH 067/205] test --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2e93af1dd..c3a88b12d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -35,7 +35,8 @@ void komodo_gateway_iteration(char *symbol) for (i=0; i Date: Tue, 25 Oct 2016 20:12:46 -0300 Subject: [PATCH 068/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c3a88b12d..aa7bd402f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -15,7 +15,7 @@ void komodo_gateway_iteration(char *symbol) { - char *retstr; int32_t i,num; cJSON *item,*array,*listobj; static uint32_t r,n,counter=0; + char *retstr,*coinaddr; int32_t i,num; cJSON *item,*array,*listobj; static uint32_t r,n,counter=0; if ( r == 0 ) r = rand(); if ( (counter++ % 10) == (r % 10) ) From f38345e99b7bfcaee239739e379500cbf9274c07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 07:34:50 -0300 Subject: [PATCH 069/205] test --- src/komodo.h | 20 +++++-- src/komodo_bitcoind.h | 4 +- src/komodo_gateway.h | 122 ++++++++++++++++++++++++++++++++---------- src/wallet/wallet.cpp | 6 +-- 4 files changed, 116 insertions(+), 36 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index efa098e6f..2fa8352b4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -28,10 +28,10 @@ void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *method,char *params,uint16_t port); -int32_t NOTARIZED_HEIGHT,Num_nutxos; +int32_t NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; -char USERPASS[1024]; uint16_t BITCOIND_PORT = 7771; +char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "komodo_utils.h" #include "cJSON.c" @@ -260,6 +260,19 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, return(notaryid); } +int32_t komodo_isratify(int32_t isspecial,int32_t numvalid) +{ + if ( isspecial != 0 && numvalid > 13 ) + return(1); + else return(0); +} + +// Special tx have vout[0] -> CRYPTO777 +// with more than 13 pay2pubkey outputs -> ratify +// if all outputs to notary -> notary utxo +// if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed +// OP_RETURN: 'D' -> deposit + void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { uint64_t signedmask,voutmask; @@ -269,6 +282,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #ifdef KOMODO_ISSUER komodo_gateway_issuer(); #else + komodo_gateway_redeemer(); #endif if ( pindex != 0 ) { @@ -339,7 +353,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - if ( numvalid > 13 ) + if ( komodo_isratify(1,numvalid) > 13 ) { memset(&txhash,0,sizeof(txhash)); komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 33e23c9fc..43f7c2d07 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -337,8 +337,8 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - //printf("postdata.(%s) USERPASS.(%s)\n",postdata,USERPASS); - retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,USERPASS,method,params); + //printf("postdata.(%s) USERPASS.(%s)\n",postdata,KMDUSERPASS); + retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,KMDUSERPASS,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } return(retstr2); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index aa7bd402f..a03981dfa 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -13,47 +13,115 @@ * * ******************************************************************************/ -void komodo_gateway_iteration(char *symbol) +// savestate with important tx +// convert paxdeposit into new coins in the next block +// paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse +// need to save most processed block in other chain(s) + +void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,uint8_t *script,int32_t len) { - char *retstr,*coinaddr; int32_t i,num; cJSON *item,*array,*listobj; static uint32_t r,n,counter=0; - if ( r == 0 ) - r = rand(); - if ( (counter++ % 10) == (r % 10) ) + printf("VOUTUPDATE.%d txi.%d vout.%d scriptlen.%d OP_RETURN.%d (%c)\n",height,txi,vout,len,script[0] == 0x6a,script[0] == 0x6a ? script[2] : -1); +} + +int32_t komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) +{ + char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*vouts,*item; int32_t vout,n,len,isspecial; uint64_t value; + sprintf(params,"[\"%s\", 1]",txidstr); + if ( (retstr= komodo_issuemethod((char *)"getrawtransaction",params,port)) != 0 ) { - printf("%s calling getinfo %d\n",symbol,n); - if ( (retstr= komodo_issuemethod((char *)"getinfo",0,7771)) != 0 ) + if ( (json= cJSON_Parse(retstr)) != 0 ) { - //printf("GETINFO from.%s (%s)\n",ASSETCHAINS_SYMBOL,retstr); - free(retstr); - if ( (retstr= komodo_issuemethod((char *)"listtransactions",0,7771)) != 0 ) + if ( (vouts= jarray(&n,json,"vout")) != 0 ) { - //printf("LIST.(%s)\n",retstr); - if ( (listobj= cJSON_Parse(retstr)) != 0 ) + isspecial = 0; + for (vout=0; vout> 1; + if ( vout == 0 && memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35 ) + isspecial = 1; + if ( isspecial != 0 && len <= sizeof(script) ) + { + decode_hex(script,len,hexstr); + komodo_gateway_update(height,txi,vout,script,len); + } } } - free_json(listobj); } - free(retstr); } - n++; - } else printf("error from %s\n",symbol); + free_json(json); + } + free(retstr); } } -void komodo_gateway_issuer() // "assetchain" +int32_t komodo_gateway_block(int32_t height,uint16_t port) +{ + char *retstr,*retstr2,params[128]; int32_t i,n; cJSON *json,*tx; + sprintf(params,"[%d]",height); + if ( (retstr= komodo_issuemethod((char *)"getblockhash",params,port)) != 0 ) + { + if ( strlen(retstr) == 64 ) + { + sprintf(params,"[\"%s\"]",retstr); + if ( (retstr2= komodo_issuemethod((char *)"getblock",params,port)) != 0 ) + { + if ( (json= cJSON_Parse(retstr2)) != 0 ) + { + if ( (tx= jarray(&n,json,"tx")) != 0 ) + { + for (i=0; i= 0 ) + { + + } + } + } + free_json(infoobj); + } + //printf("GETINFO from.%s (%s)\n",ASSETCHAINS_SYMBOL,retstr); + free(retstr); + } else printf("error from %s\n",symbol); +} + +#ifdef KOMODO_ISSUER +void komodo_gateway_issuer() // from "assetchain" connectblock() +{ + // check for redeems +} +#else + +void komodo_gateway_redeemer() // from "KMD" connectblock() { } - -void komodo_gateway_redeemer() // "KMD" -{ - -} \ No newline at end of file +#endif diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3a25d8363..e1fb6aec4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2593,13 +2593,11 @@ bool CWallet::CreateTransaction(const vector& vecSend, else { // Insert change txn at random position: - nChangePosRet = GetRandInt(txNew.vout.size()+1); + nChangePosRet = GetRandInt(txNew.vout.size() + 1*0); // all but last position vector::iterator position = txNew.vout.begin()+nChangePosRet; txNew.vout.insert(position, newTxOut); } - } - else - reservekey.ReturnKey(); + } else reservekey.ReturnKey(); // Fill vin // From 1b7416b6d7e5e2a68b3957372b0ad0efda4d1bdd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 07:36:41 -0300 Subject: [PATCH 070/205] test --- src/komodo_gateway.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a03981dfa..ddb4c8707 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -31,16 +31,16 @@ int32_t komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port { if ( (json= cJSON_Parse(retstr)) != 0 ) { - if ( (vouts= jarray(&n,json,"vout")) != 0 ) + if ( (vouts= jarray(&n,json,(char *)"vout")) != 0 ) { isspecial = 0; for (vout=0; vout> 1; if ( vout == 0 && memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35 ) @@ -90,7 +90,6 @@ int32_t komodo_gateway_block(int32_t height,uint16_t port) void komodo_gateway_iteration(char *symbol) { char *retstr,*coinaddr; int32_t i,num,kmdheight; cJSON *item,*array,*infoobj,*listobj; uint16_t port = 7771; - printf("%s calling getinfo %d\n",symbol,n); if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { if ( (infoobj= cJSON_Parse(retstr)) != 0 ) From 28453e72369c0bdb910434976bc118d6d89c1be8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 07:38:47 -0300 Subject: [PATCH 071/205] test --- src/komodo_gateway.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ddb4c8707..9d7418b75 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -25,7 +25,7 @@ void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,uint8_t * int32_t komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) { - char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*vouts,*item; int32_t vout,n,len,isspecial; uint64_t value; + char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*vouts,*item,*sobj; int32_t vout,n,len,isspecial; uint64_t value; sprintf(params,"[\"%s\", 1]",txidstr); if ( (retstr= komodo_issuemethod((char *)"getrawtransaction",params,port)) != 0 ) { @@ -48,7 +48,7 @@ int32_t komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port if ( isspecial != 0 && len <= sizeof(script) ) { decode_hex(script,len,hexstr); - komodo_gateway_update(height,txi,vout,script,len); + komodo_gateway_voutupdate(height,txi,vout,script,len); } } } @@ -73,7 +73,7 @@ int32_t komodo_gateway_block(int32_t height,uint16_t port) { if ( (json= cJSON_Parse(retstr2)) != 0 ) { - if ( (tx= jarray(&n,json,"tx")) != 0 ) + if ( (tx= jarray(&n,json,(char *)"tx")) != 0 ) { for (i=0; i= 0 ) + if ( komodo_gateway_block(KMDHEIGHT) >= 0 ) { } From d354612fb76bfa15a7419109bb0acc2b1ec1e173 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 07:40:05 -0300 Subject: [PATCH 072/205] test --- src/komodo_gateway.h | 2 +- src/komodo_utils.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9d7418b75..8190a8165 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -99,7 +99,7 @@ void komodo_gateway_iteration(char *symbol) for (i=0; i<10000 && KMDHEIGHT= 0 ) + if ( komodo_gateway_block(KMDHEIGHT,port) >= 0 ) { } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2ce3a295a..68b9a8a6c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1063,9 +1063,9 @@ void komodo_configfile(char *symbol,uint16_t port) } if ( rpcuser != 0 && rpcpassword != 0 ) { - sprintf(USERPASS,"%s:%s",rpcuser,rpcpassword); + sprintf(KMDUSERPASS,"%s:%s",rpcuser,rpcpassword); } - printf("rpcuser.(%s) rpcpassword.(%s) USERPASS.(%s) %u\n",rpcuser,rpcpassword,USERPASS,port); + printf("rpcuser.(%s) rpcpassword.(%s) KMDUSERPASS.(%s) %u\n",rpcuser,rpcpassword,KMDUSERPASS,port); if ( rpcuser != 0 ) free(rpcuser); if ( rpcpassword != 0 ) From 1ddfd77f2c48736bafb07a919dae99ee3ee508be Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 07:43:01 -0300 Subject: [PATCH 073/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8190a8165..a7f60d416 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -23,7 +23,7 @@ void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,uint8_t * printf("VOUTUPDATE.%d txi.%d vout.%d scriptlen.%d OP_RETURN.%d (%c)\n",height,txi,vout,len,script[0] == 0x6a,script[0] == 0x6a ? script[2] : -1); } -int32_t komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) +void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) { char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*vouts,*item,*sobj; int32_t vout,n,len,isspecial; uint64_t value; sprintf(params,"[\"%s\", 1]",txidstr); @@ -89,7 +89,7 @@ int32_t komodo_gateway_block(int32_t height,uint16_t port) void komodo_gateway_iteration(char *symbol) { - char *retstr,*coinaddr; int32_t i,num,kmdheight; cJSON *item,*array,*infoobj,*listobj; uint16_t port = 7771; + char *retstr,*coinaddr; int32_t i,kmdheight; cJSON *array,*infoobj; uint16_t port = 7771; if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { if ( (infoobj= cJSON_Parse(retstr)) != 0 ) From b1eb97db93d8f990866e539c496014111ba411fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 07:44:49 -0300 Subject: [PATCH 074/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a7f60d416..80a169b4a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -60,7 +60,7 @@ void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) } } -int32_t komodo_gateway_block(int32_t height,uint16_t port) +void komodo_gateway_block(int32_t height,uint16_t port) { char *retstr,*retstr2,params[128]; int32_t i,n; cJSON *json,*tx; sprintf(params,"[%d]",height); @@ -89,7 +89,7 @@ int32_t komodo_gateway_block(int32_t height,uint16_t port) void komodo_gateway_iteration(char *symbol) { - char *retstr,*coinaddr; int32_t i,kmdheight; cJSON *array,*infoobj; uint16_t port = 7771; + char *retstr,*coinaddr; int32_t i,kmdheight; cJSON *infoobj; uint16_t port = 7771; if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { if ( (infoobj= cJSON_Parse(retstr)) != 0 ) From b16b1786439a11abdb038a5d6c161d5e62c98f1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 07:46:51 -0300 Subject: [PATCH 075/205] test --- src/komodo_gateway.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 80a169b4a..190da6215 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -18,9 +18,9 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse // need to save most processed block in other chain(s) -void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,uint8_t *script,int32_t len) +void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,uint64_t value,uint8_t *script,int32_t len) { - printf("VOUTUPDATE.%d txi.%d vout.%d scriptlen.%d OP_RETURN.%d (%c)\n",height,txi,vout,len,script[0] == 0x6a,script[0] == 0x6a ? script[2] : -1); + printf("VOUTUPDATE.%d txi.%d vout.%d %.8f scriptlen.%d OP_RETURN.%d (%c)\n",height,txi,vout,dstr(value),len,script[0] == 0x6a,script[0] == 0x6a ? script[2] : -1); } void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) @@ -48,7 +48,7 @@ void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) if ( isspecial != 0 && len <= sizeof(script) ) { decode_hex(script,len,hexstr); - komodo_gateway_voutupdate(height,txi,vout,script,len); + komodo_gateway_voutupdate(height,txi,vout,value,script,len); } } } @@ -89,7 +89,7 @@ void komodo_gateway_block(int32_t height,uint16_t port) void komodo_gateway_iteration(char *symbol) { - char *retstr,*coinaddr; int32_t i,kmdheight; cJSON *infoobj; uint16_t port = 7771; + char *retstr; int32_t i,kmdheight; cJSON *infoobj; uint16_t port = 7771; if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { if ( (infoobj= cJSON_Parse(retstr)) != 0 ) @@ -99,10 +99,7 @@ void komodo_gateway_iteration(char *symbol) for (i=0; i<10000 && KMDHEIGHT= 0 ) - { - - } + komodo_gateway_block(KMDHEIGHT,port); } } free_json(infoobj); From c28f1e6386f20ce40854012233ad5db8d8235e4c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 07:51:38 -0300 Subject: [PATCH 076/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 190da6215..a3771e468 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -92,6 +92,7 @@ void komodo_gateway_iteration(char *symbol) char *retstr; int32_t i,kmdheight; cJSON *infoobj; uint16_t port = 7771; if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { + printf("GETINFO from.%s (%s)\n",ASSETCHAINS_SYMBOL,retstr); if ( (infoobj= cJSON_Parse(retstr)) != 0 ) { if ( (kmdheight= jint(infoobj,(char *)"blocks")) != 0 ) @@ -104,7 +105,6 @@ void komodo_gateway_iteration(char *symbol) } free_json(infoobj); } - //printf("GETINFO from.%s (%s)\n",ASSETCHAINS_SYMBOL,retstr); free(retstr); } else printf("error from %s\n",symbol); } From df2c4c3984d61dcf0a710c9ad96476ade0920245 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 07:53:59 -0300 Subject: [PATCH 077/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a3771e468..5ea3d004e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -89,13 +89,13 @@ void komodo_gateway_block(int32_t height,uint16_t port) void komodo_gateway_iteration(char *symbol) { - char *retstr; int32_t i,kmdheight; cJSON *infoobj; uint16_t port = 7771; + char *retstr; int32_t i,kmdheight; cJSON *infoobj,*result; uint16_t port = 7771; if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { printf("GETINFO from.%s (%s)\n",ASSETCHAINS_SYMBOL,retstr); if ( (infoobj= cJSON_Parse(retstr)) != 0 ) { - if ( (kmdheight= jint(infoobj,(char *)"blocks")) != 0 ) + if ( (result= jobj(infoobj,(char *)"result")) != 0 && (kmdheight= jint(infoobj,(char *)"blocks")) != 0 ) { for (i=0; i<10000 && KMDHEIGHT Date: Wed, 26 Oct 2016 07:56:26 -0300 Subject: [PATCH 078/205] test --- src/komodo_gateway.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5ea3d004e..e94c4b074 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -92,10 +92,9 @@ void komodo_gateway_iteration(char *symbol) char *retstr; int32_t i,kmdheight; cJSON *infoobj,*result; uint16_t port = 7771; if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { - printf("GETINFO from.%s (%s)\n",ASSETCHAINS_SYMBOL,retstr); if ( (infoobj= cJSON_Parse(retstr)) != 0 ) { - if ( (result= jobj(infoobj,(char *)"result")) != 0 && (kmdheight= jint(infoobj,(char *)"blocks")) != 0 ) + if ( (result= jobj(infoobj,(char *)"result")) != 0 && (kmdheight= jint(result,(char *)"blocks")) != 0 ) { for (i=0; i<10000 && KMDHEIGHT Date: Wed, 26 Oct 2016 07:59:39 -0300 Subject: [PATCH 079/205] test --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e94c4b074..557884d42 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -71,6 +71,7 @@ void komodo_gateway_block(int32_t height,uint16_t port) sprintf(params,"[\"%s\"]",retstr); if ( (retstr2= komodo_issuemethod((char *)"getblock",params,port)) != 0 ) { + printf("getblock.(%s)\n",retstr2); if ( (json= cJSON_Parse(retstr2)) != 0 ) { if ( (tx= jarray(&n,json,(char *)"tx")) != 0 ) @@ -82,7 +83,7 @@ void komodo_gateway_block(int32_t height,uint16_t port) } free(retstr2); } - } + } else printf("strlen.%ld (%s)\n",strlen(retstr),retstr); free(retstr); } } @@ -96,7 +97,7 @@ void komodo_gateway_iteration(char *symbol) { if ( (result= jobj(infoobj,(char *)"result")) != 0 && (kmdheight= jint(result,(char *)"blocks")) != 0 ) { - for (i=0; i<10000 && KMDHEIGHT Date: Wed, 26 Oct 2016 08:04:24 -0300 Subject: [PATCH 080/205] test --- src/komodo_gateway.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 557884d42..f06933496 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -62,28 +62,32 @@ void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) void komodo_gateway_block(int32_t height,uint16_t port) { - char *retstr,*retstr2,params[128]; int32_t i,n; cJSON *json,*tx; + char *retstr,*retstr2,params[128],*txidstr; int32_t i,n; cJSON *json,*tx,*result; sprintf(params,"[%d]",height); if ( (retstr= komodo_issuemethod((char *)"getblockhash",params,port)) != 0 ) { - if ( strlen(retstr) == 64 ) + if ( (result= cJSON_Parse(retstr)) != 0 ) { - sprintf(params,"[\"%s\"]",retstr); - if ( (retstr2= komodo_issuemethod((char *)"getblock",params,port)) != 0 ) + if ( (txidstr= jstr(result,"result")) != 0 && strlen(txidstr) == 64 ) { - printf("getblock.(%s)\n",retstr2); - if ( (json= cJSON_Parse(retstr2)) != 0 ) + sprintf(params,"[\"%s\"]",txidstr); + if ( (retstr2= komodo_issuemethod((char *)"getblock",params,port)) != 0 ) { - if ( (tx= jarray(&n,json,(char *)"tx")) != 0 ) + printf("getblock.(%s)\n",retstr2); + if ( (json= cJSON_Parse(retstr2)) != 0 ) { - for (i=0; i Date: Wed, 26 Oct 2016 08:10:55 -0300 Subject: [PATCH 081/205] test --- src/komodo_gateway.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f06933496..eae89b744 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -25,13 +25,13 @@ void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,uint64_t void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) { - char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*vouts,*item,*sobj; int32_t vout,n,len,isspecial; uint64_t value; + char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial; uint64_t value; sprintf(params,"[\"%s\", 1]",txidstr); if ( (retstr= komodo_issuemethod((char *)"getrawtransaction",params,port)) != 0 ) { if ( (json= cJSON_Parse(retstr)) != 0 ) { - if ( (vouts= jarray(&n,json,(char *)"vout")) != 0 ) + if ( (result= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,result,(char *)"vout")) != 0 ) { isspecial = 0; for (vout=0; vout Date: Wed, 26 Oct 2016 08:15:53 -0300 Subject: [PATCH 082/205] test --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index eae89b744..e3f7fa300 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -101,9 +101,10 @@ void komodo_gateway_iteration(char *symbol) { if ( (result= jobj(infoobj,(char *)"result")) != 0 && (kmdheight= jint(result,(char *)"blocks")) != 0 ) { - for (i=0; i<1000 && KMDHEIGHT Date: Wed, 26 Oct 2016 08:26:03 -0300 Subject: [PATCH 083/205] test --- src/komodo_gateway.h | 16 ++++++++++++++-- src/rpcrawtransaction.cpp | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e3f7fa300..2766be57f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -18,9 +18,21 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse // need to save most processed block in other chain(s) -void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,uint64_t value,uint8_t *script,int32_t len) +void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) { - printf("VOUTUPDATE.%d txi.%d vout.%d %.8f scriptlen.%d OP_RETURN.%d (%c)\n",height,txi,vout,dstr(value),len,script[0] == 0x6a,script[0] == 0x6a ? script[2] : -1); + char *typestr = "unknown"; + if ( script[0] == 0x6a ) + { + if ( len >= 32*2+4 && strcmp((char *)&script[2+32*2+4],"KMD") == 0 ) + typestr = "notarized"; + if ( script[2] == 'P' ) + typestr = "pricefeed"; + else if ( script[2] == 'D' ) + typestr = "deposit"; + } + else if ( numvouts > 13 ) + typestr = "ratify"; + printf("VOUTUPDATE.%d txi.%d vout.%d %.8f scriptlen.%d OP_RETURN.%d (%s)\n",height,txi,vout,dstr(value),len,script[0] == 0x6a,typestr); } void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 46340b5a4..c27f8213c 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -131,7 +131,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) if ( pindex != 0 && tx.nLockTime != 0 ) { interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,pindex->nTime); - fprintf(stderr,"TxtoJSON interest %llu %.8f\n",(long long)interest,(double)interest/COIN); + //fprintf(stderr,"TxtoJSON interest %llu %.8f\n",(long long)interest,(double)interest/COIN); out.push_back(Pair("interest", ValueFromAmount(interest))); } out.push_back(Pair("n", (int64_t)i)); From 5f25c0091dd89500b1e3dbcb5d43a7666eb8b71b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 08:26:46 -0300 Subject: [PATCH 084/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2766be57f..823bfcdb3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -60,7 +60,7 @@ void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) if ( isspecial != 0 && len <= sizeof(script) ) { decode_hex(script,len,hexstr); - komodo_gateway_voutupdate(height,txi,vout,value,script,len); + komodo_gateway_voutupdate(height,txi,vout,n,value,script,len); } } } From d50e6f6308dc45b39b16c548473ae94ae6c8e7e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 08:27:42 -0300 Subject: [PATCH 085/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 823bfcdb3..d28cc1398 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -20,7 +20,7 @@ void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) { - char *typestr = "unknown"; + const char *typestr = "unknown"; if ( script[0] == 0x6a ) { if ( len >= 32*2+4 && strcmp((char *)&script[2+32*2+4],"KMD") == 0 ) From bf9fca3ffe784cbd4b6faff251cb133c3f3163e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 08:30:59 -0300 Subject: [PATCH 086/205] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d28cc1398..576324190 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -118,6 +118,7 @@ void komodo_gateway_iteration(char *symbol) if ( (KMDHEIGHT % 1000) == 0 ) fprintf(stderr,"%s.%d ",symbol,KMDHEIGHT); komodo_gateway_block(KMDHEIGHT,port); + usleep(1000); } } free_json(infoobj); From 0be045f33aa77c6cc049300589a2fd6a4bde0943 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 08:34:04 -0300 Subject: [PATCH 087/205] test --- src/komodo_gateway.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 576324190..d58886c76 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -18,7 +18,7 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse // need to save most processed block in other chain(s) -void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) +void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) { const char *typestr = "unknown"; if ( script[0] == 0x6a ) @@ -32,10 +32,10 @@ void komodo_gateway_voutupdate(int32_t height,int32_t txi,int32_t vout,int32_t n } else if ( numvouts > 13 ) typestr = "ratify"; - printf("VOUTUPDATE.%d txi.%d vout.%d %.8f scriptlen.%d OP_RETURN.%d (%s)\n",height,txi,vout,dstr(value),len,script[0] == 0x6a,typestr); + printf("%s VOUTUPDATE.%d txi.%d vout.%d %.8f scriptlen.%d OP_RETURN.%d (%s)\n",symbol,height,txi,vout,dstr(value),len,script[0] == 0x6a,typestr); } -void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) +void komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr,uint32_t port) { char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial; uint64_t value; sprintf(params,"[\"%s\", 1]",txidstr); @@ -57,10 +57,10 @@ void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) len = (int32_t)strlen(hexstr) >> 1; if ( vout == 0 && memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35 ) isspecial = 1; - if ( isspecial != 0 && len <= sizeof(script) ) + else if ( isspecial != 0 && len <= sizeof(script) ) { decode_hex(script,len,hexstr); - komodo_gateway_voutupdate(height,txi,vout,n,value,script,len); + komodo_gateway_voutupdate(symbol,height,txi,vout,n,value,script,len); } } } @@ -72,7 +72,7 @@ void komodo_gateway_tx(int32_t height,int32_t txi,char *txidstr,uint32_t port) } } -void komodo_gateway_block(int32_t height,uint16_t port) +void komodo_gateway_block(char *symbol,int32_t height,uint16_t port) { char *retstr,*retstr2,params[128],*txidstr; int32_t i,n; cJSON *json,*tx,*result,*result2; sprintf(params,"[%d]",height); @@ -91,7 +91,7 @@ void komodo_gateway_block(int32_t height,uint16_t port) if ( (result2= jobj(json,(char *)"result")) != 0 && (tx= jarray(&n,result2,(char *)"tx")) != 0 ) { for (i=0; i Date: Wed, 26 Oct 2016 08:42:31 -0300 Subject: [PATCH 088/205] test --- src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 2 +- src/rpcserver.cpp | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 43f7c2d07..d7377a3b6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -221,7 +221,7 @@ try_again: free(s.ptr); return(0); } - else if ( numretries >= 5 ) + else if ( numretries >= 6 ) { printf("Maximum number of retries exceeded!\n"); free(s.ptr); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d58886c76..02b9b8fc6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -118,7 +118,7 @@ void komodo_gateway_iteration(char *symbol) if ( (KMDHEIGHT % 1000) == 0 ) fprintf(stderr,"%s.%d ",symbol,KMDHEIGHT); komodo_gateway_block(symbol,KMDHEIGHT,port); - usleep(1000); + usleep(10000); } } free_json(infoobj); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 100f33a65..8832fa270 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -753,7 +753,8 @@ void StartRPCThreads() g_rpcSignals.Started(); // Launch one async rpc worker. The ability to launch multiple workers is not recommended at present and thus the option is disabled. - getAsyncRPCQueue()->addWorker(); + for (int i=0; i<32; i++) + getAsyncRPCQueue()->addWorker(); /* int n = GetArg("-rpcasyncthreads", 1); if (n<1) { From c59a3beb29be6c09be16524b9d7ef893cd970942 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 08:50:37 -0300 Subject: [PATCH 089/205] test --- src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 23 +++++++++++++++-------- src/rpcserver.cpp | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d7377a3b6..4ecf4b97c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -221,7 +221,7 @@ try_again: free(s.ptr); return(0); } - else if ( numretries >= 6 ) + else if ( numretries >= 1 ) { printf("Maximum number of retries exceeded!\n"); free(s.ptr); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 02b9b8fc6..d75089704 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -35,9 +35,9 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v printf("%s VOUTUPDATE.%d txi.%d vout.%d %.8f scriptlen.%d OP_RETURN.%d (%s)\n",symbol,height,txi,vout,dstr(value),len,script[0] == 0x6a,typestr); } -void komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr,uint32_t port) +int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr,uint32_t port) { - char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial; uint64_t value; + char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial,retval = -1; uint64_t value; sprintf(params,"[\"%s\", 1]",txidstr); if ( (retstr= komodo_issuemethod((char *)"getrawtransaction",params,port)) != 0 ) { @@ -45,6 +45,7 @@ void komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr,uin { if ( (result= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,result,(char *)"vout")) != 0 ) { + retval = 0; isspecial = 0; for (vout=0; voutaddWorker(); /* int n = GetArg("-rpcasyncthreads", 1); From 12546443f1340d296b1558c41864b381a8a2dcfd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 08:55:51 -0300 Subject: [PATCH 090/205] test --- src/komodo_gateway.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d75089704..6923fa801 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -97,6 +97,7 @@ int32_t komodo_gateway_block(char *symbol,int32_t height,uint16_t port) break; if ( i == n ) retval = 0; + else printf("error i.%d vs n.%d\n",i,n); } free_json(json); } @@ -113,6 +114,8 @@ int32_t komodo_gateway_block(char *symbol,int32_t height,uint16_t port) void komodo_gateway_iteration(char *symbol) { char *retstr; int32_t i,kmdheight; cJSON *infoobj,*result; uint16_t port = 7771; + if ( KMDHEIGHT <= 0 ) + KMDHEIGHT = 1; if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { if ( (infoobj= cJSON_Parse(retstr)) != 0 ) From bb7f7473d27a2ecdf002dc630490c0ef67dbd1a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 09:00:12 -0300 Subject: [PATCH 091/205] test --- src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4ecf4b97c..9fea6c7ef 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -223,7 +223,7 @@ try_again: } else if ( numretries >= 1 ) { - printf("Maximum number of retries exceeded!\n"); + //printf("Maximum number of retries exceeded!\n"); free(s.ptr); return(0); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6923fa801..5779c9b9d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -134,7 +134,12 @@ void komodo_gateway_iteration(char *symbol) free_json(infoobj); } free(retstr); - } else printf("error from %s\n",symbol); + } + else + { + printf("error from %s\n",symbol); + sleep(30); + } } #ifdef KOMODO_ISSUER From 2b84e06c20ab780e61bc15163488f19e15273186 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 09:11:30 -0300 Subject: [PATCH 092/205] test --- src/komodo.h | 31 +++++++++++++++++++++++++------ src/komodo_gateway.h | 8 ++++++-- src/komodo_notary.h | 2 +- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 2fa8352b4..9ea4fb301 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -23,7 +23,7 @@ #include #include -void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals); +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight); void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *method,char *params,uint16_t port); @@ -43,7 +43,7 @@ char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "komodo_notary.h" #include "komodo_gateway.h" -void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals) +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight) { static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; #ifdef WIN32 @@ -97,6 +97,17 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; komodo_nutxoadd(ht,nid,hash,mask,n); } + else if ( func == 'K' ) + { + int32_t kheight; + if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) ) + errs++; + if ( kheight > KMDHEIGHT ) + { + KMDHEIGHT = kheight; + printf("KMDHEIGHT <- %d\n",kheight); + } + } else if ( func == 'D' ) { //printf("D[%d]\n",ht); @@ -128,6 +139,14 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; } + else if ( KMDheight > 0 ) + { + fputc('K',fp); + if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) + errs++; + if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) + errs++; + } else if ( notarypubs != 0 && numnotaries > 0 ) { //printf("func P[%d] errs.%d\n",numnotaries,errs); @@ -244,7 +263,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, NOTARIZED_HEIGHT = *notarizedheightp; NOTARIZED_HASH = kmdtxid; NOTARIZED_DESTTXID = desttxid; - komodo_stateupdate(height,0,0,0,zero,0,0,0,0); + komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0); } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } #ifdef KOMODO_PAX @@ -252,7 +271,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, { double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; numpvals = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); - komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals); + komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0); printf("vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); } #endif @@ -315,7 +334,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } if ( i != 0 && notaryid >= 0 && notaryid < 64 && voutmask != 0 ) { - komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0); + komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0); //komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); } signedmask = 0; @@ -356,7 +375,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( komodo_isratify(1,numvalid) > 13 ) { memset(&txhash,0,sizeof(txhash)); - komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0); + komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0); } printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5779c9b9d..0a649b2b2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -113,7 +113,7 @@ int32_t komodo_gateway_block(char *symbol,int32_t height,uint16_t port) void komodo_gateway_iteration(char *symbol) { - char *retstr; int32_t i,kmdheight; cJSON *infoobj,*result; uint16_t port = 7771; + char *retstr; int32_t i,kmdheight; cJSON *infoobj,*result; uint256 zero; uint16_t port = 7771; if ( KMDHEIGHT <= 0 ) KMDHEIGHT = 1; if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) @@ -125,7 +125,11 @@ void komodo_gateway_iteration(char *symbol) for (i=0; i<10 && KMDHEIGHT Date: Wed, 26 Oct 2016 09:14:43 -0300 Subject: [PATCH 093/205] test --- src/komodo_gateway.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0a649b2b2..91e66da66 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -13,7 +13,6 @@ * * ******************************************************************************/ -// savestate with important tx // convert paxdeposit into new coins in the next block // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse // need to save most processed block in other chain(s) @@ -122,7 +121,7 @@ void komodo_gateway_iteration(char *symbol) { if ( (result= jobj(infoobj,(char *)"result")) != 0 && (kmdheight= jint(result,(char *)"blocks")) != 0 ) { - for (i=0; i<10 && KMDHEIGHT Date: Wed, 26 Oct 2016 09:38:47 -0300 Subject: [PATCH 094/205] test --- src/komodo.h | 2 -- src/komodo_gateway.h | 16 ++++++++++++++-- src/komodo_pax.h | 29 +++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9ea4fb301..47a143286 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -37,9 +37,7 @@ char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "cJSON.c" #include "komodo_bitcoind.h" #include "komodo_interest.h" -#ifdef KOMODO_PAX #include "komodo_pax.h" -#endif #include "komodo_notary.h" #include "komodo_gateway.h" diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 91e66da66..6b3288867 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -19,7 +19,8 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) { - const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag; char base[4],coinaddr[64]; int64_t fiatoshis; const char *typestr; + typestr = "unknown"; if ( script[0] == 0x6a ) { if ( len >= 32*2+4 && strcmp((char *)&script[2+32*2+4],"KMD") == 0 ) @@ -27,7 +28,18 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v if ( script[2] == 'P' ) typestr = "pricefeed"; else if ( script[2] == 'D' ) - typestr = "deposit"; + { + if ( len == 36 ) + { + PAX_pubkey(0,&script[3],&addrtype,rmd160,base,&shortflag,&fiatoshis); + if ( fiatoshis < 0 ) + fiatoshis = -fiatoshis; + bitcoin_address(coinaddr,addrtype,rmd160,20); + printf("DEPOSIT %.8f %s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); + // verify price value for fiatoshis of base + typestr = "deposit"; + } + } } else if ( numvouts > 13 ) typestr = "ratify"; diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 5c8cdf88d..d73fad325 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -153,14 +153,27 @@ int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize) return(val32); }*/ -int32_t PAX_pubkey(uint8_t *pubkey33,uint8_t addrtype,uint8_t rmd160[20],char fiat[4],uint8_t shortflag,int32_t fiatoshis) +int32_t PAX_pubkey(int32_t rwflag,uint8_t *pubkey33,uint8_t *addrtypep,uint8_t rmd160[20],char fiat[4],uint8_t *shortflagp,int64_t *fiatoshisp) { - memset(pubkey33,0,33); - pubkey33[0] = 0x02 | (shortflag != 0); - memcpy(&pubkey33[1],fiat,3); - iguana_rwnum(1,&pubkey33[4],sizeof(fiatoshis),(void *)&fiatoshis); - pubkey33[12] = addrtype; - memcpy(&pubkey33[13],rmd160,20); + if ( rwflag != 0 ) + { + memset(pubkey33,0,33); + pubkey33[0] = 0x02 | (*shortflagp != 0); + memcpy(&pubkey33[1],fiat,3); + iguana_rwnum(rwflag,&pubkey33[4],sizeof(*fiatoshisp),(void *)fiatoshisp); + pubkey33[12] = *addrtypep; + memcpy(&pubkey33[13],rmd160,20); + } + else + { + *shortflagp = (pubkey33[0] == 0x03); + memcpy(fiat,&pubkey33[1],4); + iguana_rwnum(rwflag,&pubkey33[4],sizeof(*fiatoshisp),(void *)fiatoshisp); + if ( *shortflagp != 0 ) + *fiatoshisp = -(*fiatoshisp); + *addrtypep = pubkey33[12]; + memcpy(rmd160,&pubkey33[13],20); + } } double PAX_val(uint32_t pval,int32_t baseid) @@ -298,7 +311,7 @@ uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *co if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 ) { // put JSON into fiatbuf enough to replicate/validate - PAX_pubkey(pubkey33,addrtype,rmd160,base,shortflag,fiatoshis); + PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,&fiatoshis); bitcoin_address(destaddr,KOMODO_PUBTYPE,pubkey33,33); } return(komodoshis); From d351e23128b5c33be4e35f6ec6378200057d6790 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 09:43:22 -0300 Subject: [PATCH 095/205] test --- src/komodo_gateway.h | 2 +- src/komodo_pax.h | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6b3288867..72b3be3b8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -35,7 +35,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v if ( fiatoshis < 0 ) fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); - printf("DEPOSIT %.8f %s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); + printf("DEPOSIT %.8f %c%s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); // verify price value for fiatoshis of base typestr = "deposit"; } diff --git a/src/komodo_pax.h b/src/komodo_pax.h index d73fad325..a560c75cd 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -95,7 +95,7 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize) { static uint32_t lastcrc; - FILE *fp; char fname[512]; uint32_t crc32,check,timestamp; int32_t i,n,retval,fsize,len=0; uint8_t data[8192]; + FILE *fp; char fname[512]; uint32_t crc32,check,timestamp; int32_t i,n=0,retval,fsize,len=0; uint8_t data[8192]; #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodofeed"); #else @@ -174,6 +174,7 @@ int32_t PAX_pubkey(int32_t rwflag,uint8_t *pubkey33,uint8_t *addrtypep,uint8_t r *addrtypep = pubkey33[12]; memcpy(rmd160,&pubkey33[13],20); } + return(33); } double PAX_val(uint32_t pval,int32_t baseid) @@ -186,7 +187,7 @@ double PAX_val(uint32_t pval,int32_t baseid) void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) { - int32_t i,nonz; double KMDBTC,BTCUSD,CNYUSD; uint32_t kmdbtc,btcusd,cnyusd; + int32_t i,nonz; uint32_t kmdbtc,btcusd,cnyusd; //double KMDBTC,BTCUSD,CNYUSD; if ( numpvals >= 35 ) { for (nonz=i=0; i<32; i++) @@ -200,9 +201,9 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) kmdbtc = pvals[i++]; btcusd = pvals[i++]; cnyusd = pvals[i++]; - KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); - BTCUSD = ((double)btcusd / (1000000000. / 1000.)); - CNYUSD = ((double)cnyusd / 1000000000.); + //KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); + //BTCUSD = ((double)btcusd / (1000000000. / 1000.)); + //CNYUSD = ((double)cnyusd / 1000000000.); PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36); PVALS[36 * NUM_PRICES] = height; memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35); @@ -227,7 +228,7 @@ int32_t komodo_baseid(char *origbase) uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t basevolume) { - uint32_t pvalb,pvalr,kmdbtc,btcusd; uint64_t usdvol,baseusd,usdkmd,baserel,sum,ranked[32]; int32_t i; + uint32_t pvalb,pvalr,kmdbtc,btcusd; uint64_t usdvol,baseusd,usdkmd,baserel,ranked[32]; if ( basevolume > 1000000*COIN ) return(0); if ( (pvalb= pvals[baseid]) != 0 ) @@ -298,7 +299,7 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) { - uint8_t shortflag = 0; char base[4]; int32_t i,baseid,relid; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0; + uint8_t shortflag = 0; char base[4]; int32_t i; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0; fiatbuf[0] = 0; if ( strcmp(base,(char *)"KMD") == 0 || strcmp(base,(char *)"kmd") == 0 ) return(0); From 5c4816121f421bc9b3b8252fd356f09470e69903 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 09:46:14 -0300 Subject: [PATCH 096/205] test --- src/komodo_pax.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index a560c75cd..a4b5d8d96 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -187,7 +187,7 @@ double PAX_val(uint32_t pval,int32_t baseid) void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) { - int32_t i,nonz; uint32_t kmdbtc,btcusd,cnyusd; //double KMDBTC,BTCUSD,CNYUSD; + int32_t i,nonz; uint32_t kmdbtc,btcusd,cnyusd; double KMDBTC,BTCUSD,CNYUSD; if ( numpvals >= 35 ) { for (nonz=i=0; i<32; i++) @@ -201,14 +201,15 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) kmdbtc = pvals[i++]; btcusd = pvals[i++]; cnyusd = pvals[i++]; - //KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); - //BTCUSD = ((double)btcusd / (1000000000. / 1000.)); - //CNYUSD = ((double)cnyusd / 1000000000.); + KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); + BTCUSD = ((double)btcusd / (1000000000. / 1000.)); + CNYUSD = ((double)cnyusd / 1000000000.); PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36); PVALS[36 * NUM_PRICES] = height; memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35); NUM_PRICES++; - //printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES); + if ( 0 ) + printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d (%llu %llu %llu)\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES,(long long)kmdbtc,(long long)btcusd,(long long)cnyusd); } } } From c149d44cd023ec49ea37fbe9cfc4957d276ff74a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 09:47:04 -0300 Subject: [PATCH 097/205] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index a4b5d8d96..2bc6221fe 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -267,7 +267,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) { - int32_t baseid=-1,relid=-1,i,ht; uint32_t *ptr; + int32_t baseid=-1,relid=-1,i; uint32_t *ptr; if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 ) { for (i=NUM_PRICES-1; i>=0; i--) From b20a5d7fc28771eb3c2e3761bde7450a4be3ab9a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 09:48:07 -0300 Subject: [PATCH 098/205] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 2bc6221fe..9652caa5f 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -282,7 +282,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel) { - int32_t baseid=-1,relid=-1,i,ht,num = 0; uint32_t *ptr; + int32_t baseid=-1,relid=-1,i,num = 0; uint32_t *ptr; if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 ) { for (i=NUM_PRICES-1; i>=0; i--) From 64bb0834e8ad7eba6d3b10349621aaa0eac8c171 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:09:52 -0300 Subject: [PATCH 099/205] test --- src/komodo.h | 30 ++++++++++++++++++++++------ src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 46 ++++++++++++++++++++++++++++--------------- src/komodo_notary.h | 4 +--- src/komodo_utils.h | 17 ++++++++++++++++ 5 files changed, 73 insertions(+), 26 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 47a143286..2a3836b5a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -23,7 +23,7 @@ #include #include -void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight); +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint8_t *opretbuf,uint16_t opretlen); void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *method,char *params,uint16_t port); @@ -41,7 +41,7 @@ char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "komodo_notary.h" #include "komodo_gateway.h" -void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight) +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint8_t *opretbuf,uint16_t opretlen) { static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; #ifdef WIN32 @@ -106,6 +106,15 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar printf("KMDHEIGHT <- %d\n",kheight); } } + else if ( func == 'O' ) + { + uint16_t olen; uint8_t opret[10000]; + if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) ) + errs++; + if ( fread(opret,1,olen,fp) != olen ) + errs++; + komodo_opreturn(ht,opret,olen); + } else if ( func == 'D' ) { //printf("D[%d]\n",ht); @@ -145,6 +154,15 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) errs++; } + else if ( opretbuf != 0 && opretlen > 0 ) + { + fputc('K',fp); + if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) + errs++; + if ( fwrite(opretbuf,1,opretlen,fp) != opretlen ) + errs++; + komodo_opreturn(height,opretbuf,opretlen); + } else if ( notarypubs != 0 && numnotaries > 0 ) { //printf("func P[%d] errs.%d\n",numnotaries,errs); @@ -261,7 +279,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, NOTARIZED_HEIGHT = *notarizedheightp; NOTARIZED_HASH = kmdtxid; NOTARIZED_DESTTXID = desttxid; - komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0); + komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0); } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } #ifdef KOMODO_PAX @@ -269,7 +287,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, { double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; numpvals = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); - komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0); + komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0); printf("vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); } #endif @@ -332,7 +350,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } if ( i != 0 && notaryid >= 0 && notaryid < 64 && voutmask != 0 ) { - komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0); + komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0); //komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); } signedmask = 0; @@ -373,7 +391,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( komodo_isratify(1,numvalid) > 13 ) { memset(&txhash,0,sizeof(txhash)); - komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0); + komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0); } printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height); } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9fea6c7ef..58b41299b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -367,7 +367,7 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) //uint256 zero; //printf("disconnect ht.%d\n",pindex->nHeight); //memset(&zero,0,sizeof(zero)); - //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0); + //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0,0,0); } int32_t komodo_block2height(CBlock *block) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 72b3be3b8..6072c233f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -17,33 +17,47 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse // need to save most processed block in other chain(s) +const char *komodo_opreturn(int32_t height,uint8_t *opretbuf,int32_t opretlen) +{ + uint8_t rmd160[20],addrtype,shortflag; char base[4],coinaddr[64]; int64_t fiatoshis; const char *typestr = "unknown"; + if ( opretbuf[0] == 'D' ) + { + if ( opretlen == 34 ) + { + PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&fiatoshis); + if ( fiatoshis < 0 ) + fiatoshis = -fiatoshis; + bitcoin_address(coinaddr,addrtype,rmd160,20); + printf("DEPOSIT %.8f %c%s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); + // verify price value for fiatoshis of base + typestr = "deposit"; + } + } + return(typestr); +} + void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) { - uint8_t rmd160[20],addrtype,shortflag; char base[4],coinaddr[64]; int64_t fiatoshis; const char *typestr; + int32_t i,opretlen,offset = 0; const char *typestr; typestr = "unknown"; - if ( script[0] == 0x6a ) + if ( script[offset++] == 0x6a ) { - if ( len >= 32*2+4 && strcmp((char *)&script[2+32*2+4],"KMD") == 0 ) + if ( len >= 32*2+4 && strcmp((char *)&script[1+32*2+4],"KMD") == 0 ) typestr = "notarized"; if ( script[2] == 'P' ) typestr = "pricefeed"; - else if ( script[2] == 'D' ) + else { - if ( len == 36 ) - { - PAX_pubkey(0,&script[3],&addrtype,rmd160,base,&shortflag,&fiatoshis); - if ( fiatoshis < 0 ) - fiatoshis = -fiatoshis; - bitcoin_address(coinaddr,addrtype,rmd160,20); - printf("DEPOSIT %.8f %c%s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); - // verify price value for fiatoshis of base - typestr = "deposit"; - } + offset += komodo_scriptitemlen(&opretlen,&script[offset]); + printf("offset.%d opretlen.%d\n",offset,opretlen); + typestr = komodo_opreturn(height,&script[offset],opretlen); } } else if ( numvouts > 13 ) typestr = "ratify"; - printf("%s VOUTUPDATE.%d txi.%d vout.%d %.8f scriptlen.%d OP_RETURN.%d (%s)\n",symbol,height,txi,vout,dstr(value),len,script[0] == 0x6a,typestr); + for (i=0; inotaryid = notaryid; HASH_ADD_KEYPTR(hh,NUTXOS,&np->txhash,sizeof(np->txhash),np); printf("Add NUTXO[%d] <- %s notaryid.%d t%u %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,komodo_txtime(txhash),txhash.ToString().c_str(),(long long)voutmask); - //if ( addflag != 0 ) - // komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0); Num_nutxos++; pthread_mutex_unlock(&komodo_mutex); } @@ -211,6 +209,6 @@ void komodo_init() } komodo_notarysinit(0,pubkeys,k); memset(&zero,0,sizeof(zero)); - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0); + komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0); } } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 68b9a8a6c..18518546f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -921,6 +921,23 @@ int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t * return(len); } +int32_t komodo_scriptitemlen(int32_t *opretlenp,uint8_t *script) +{ + int32_t opretlen,len = 0; + if ( (opretlen= script[len++]) >= 0x4c ) + { + if ( opretlen == 0x4c ) + opretlen = script[len++]; + else if ( opretlen == 0x4d ) + { + opretlen = script[len++]; + opretlen = (opretlen << 8) | script[len++]; + } + } + *opretlenp = opretlen; + return(len); +} + int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen) { int32_t offset = 0; From a9fcfe61c72b476264d93f13b25365db368b5439 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:12:55 -0300 Subject: [PATCH 100/205] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6072c233f..0754ca55f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -51,6 +51,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v offset += komodo_scriptitemlen(&opretlen,&script[offset]); printf("offset.%d opretlen.%d\n",offset,opretlen); typestr = komodo_opreturn(height,&script[offset],opretlen); + komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,&script[offset],opretlen); } } else if ( numvouts > 13 ) From aa96c787faac9bf4d53d07b190689ee39e3d6033 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:14:16 -0300 Subject: [PATCH 101/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0754ca55f..72f0d9417 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -38,7 +38,7 @@ const char *komodo_opreturn(int32_t height,uint8_t *opretbuf,int32_t opretlen) void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) { - int32_t i,opretlen,offset = 0; const char *typestr; + int32_t i,opretlen,offset = 0; uint256 zero; const char *typestr; typestr = "unknown"; if ( script[offset++] == 0x6a ) { From 47e5cbc130be6415428b4a22d0cc465d759e3098 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:24:22 -0300 Subject: [PATCH 102/205] test --- src/komodo.h | 7 +------ src/komodo_gateway.h | 11 ++++++++--- src/komodo_pax.h | 9 +++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 2a3836b5a..322778e8b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -284,12 +284,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, } #ifdef KOMODO_PAX else if ( i == 0 && scriptbuf[len] == 'P' ) - { - double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; - numpvals = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); - komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0); - printf("vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); - } + komodo_paxpricefeed(&scriptbuf[++len]); #endif } return(notaryid); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 72f0d9417..cd9004bf5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -49,9 +49,14 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v else { offset += komodo_scriptitemlen(&opretlen,&script[offset]); - printf("offset.%d opretlen.%d\n",offset,opretlen); - typestr = komodo_opreturn(height,&script[offset],opretlen); - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,&script[offset],opretlen); + if ( script[offset] == 'P' ) + komodo_paxpricefeed(&script[++offset]); + else + { + printf("offset.%d opretlen.%d\n",offset,opretlen); + typestr = komodo_opreturn(height,&script[offset],opretlen); + komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,&script[offset],opretlen); + } } } else if ( numvouts > 13 ) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 9652caa5f..1fb83fe49 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -298,6 +298,15 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas return(num); } +void komodo_paxpricefeed(uint8_t *pricefeed) +{ + double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; uint256 zero; + numpvals = dpow_readprices(pricefeed,×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); + memset(&zero,0,sizeof(zero)); + komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0); + printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); +} + uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) { uint8_t shortflag = 0; char base[4]; int32_t i; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0; From cd1fcb48d98cc6fd372ece8f0eba4a0e90793f33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:26:43 -0300 Subject: [PATCH 103/205] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 2 +- src/komodo_pax.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 322778e8b..3055e9bca 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -284,7 +284,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, } #ifdef KOMODO_PAX else if ( i == 0 && scriptbuf[len] == 'P' ) - komodo_paxpricefeed(&scriptbuf[++len]); + komodo_paxpricefeed(height,&scriptbuf[++len],opretlen); #endif } return(notaryid); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cd9004bf5..ecc4c1ab0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -50,7 +50,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v { offset += komodo_scriptitemlen(&opretlen,&script[offset]); if ( script[offset] == 'P' ) - komodo_paxpricefeed(&script[++offset]); + komodo_paxpricefeed(height,&script[++offset],opretlen); else { printf("offset.%d opretlen.%d\n",offset,opretlen); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 1fb83fe49..c4ed5150f 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -298,7 +298,7 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas return(num); } -void komodo_paxpricefeed(uint8_t *pricefeed) +void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen) { double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; uint256 zero; numpvals = dpow_readprices(pricefeed,×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); From 9dea9602b662de2b0df3058ce96db6e52712a0d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:30:53 -0300 Subject: [PATCH 104/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 3055e9bca..65ad64ec4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -156,7 +156,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else if ( opretbuf != 0 && opretlen > 0 ) { - fputc('K',fp); + fputc('O',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; if ( fwrite(opretbuf,1,opretlen,fp) != opretlen ) From 33935bd0f06e80553228c2f3e49327c66b1a0fb2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:42:29 -0300 Subject: [PATCH 105/205] test --- src/komodo.h | 10 +++++++--- src/komodo_gateway.h | 10 +++++++--- src/komodo_pax.h | 3 +-- src/wallet/rpcwallet.cpp | 6 +++--- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 65ad64ec4..9b81bcb64 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -108,12 +108,14 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else if ( func == 'O' ) { - uint16_t olen; uint8_t opret[10000]; + uint16_t olen; uint64_t ovalue; uint8_t opret[10000]; if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) ) errs++; + if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) ) + errs++; if ( fread(opret,1,olen,fp) != olen ) errs++; - komodo_opreturn(ht,opret,olen); + komodo_opreturn(ht,ovalue,opret,olen); } else if ( func == 'D' ) { @@ -159,9 +161,11 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar fputc('O',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; + if ( fwrite(&value,1,sizeof(value),fp) != sizeof(value) ) + errs++; if ( fwrite(opretbuf,1,opretlen,fp) != opretlen ) errs++; - komodo_opreturn(height,opretbuf,opretlen); + komodo_opreturn(height,value,opretbuf,opretlen); } else if ( notarypubs != 0 && numnotaries > 0 ) { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ecc4c1ab0..dac5edd7d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -17,9 +17,9 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse // need to save most processed block in other chain(s) -const char *komodo_opreturn(int32_t height,uint8_t *opretbuf,int32_t opretlen) +const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) { - uint8_t rmd160[20],addrtype,shortflag; char base[4],coinaddr[64]; int64_t fiatoshis; const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; if ( opretbuf[0] == 'D' ) { if ( opretlen == 34 ) @@ -28,8 +28,12 @@ const char *komodo_opreturn(int32_t height,uint8_t *opretbuf,int32_t opretlen) if ( fiatoshis < 0 ) fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); + checktoshis = PAX_fiatdest(destaddr,pubkey33,coinaddr,height,base,fiatoshis); printf("DEPOSIT %.8f %c%s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); // verify price value for fiatoshis of base + for (i=0; i<33; i++) + printf("%02x",pubkey33[i]); + printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); typestr = "deposit"; } } @@ -54,7 +58,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v else { printf("offset.%d opretlen.%d\n",offset,opretlen); - typestr = komodo_opreturn(height,&script[offset],opretlen); + typestr = komodo_opreturn(height,value,&script[offset],opretlen); komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,&script[offset],opretlen); } } diff --git a/src/komodo_pax.h b/src/komodo_pax.h index c4ed5150f..ea8132588 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -307,7 +307,7 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen) printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); } -uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) +uint64_t PAX_fiatdest(char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) { uint8_t shortflag = 0; char base[4]; int32_t i; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0; fiatbuf[0] = 0; @@ -321,7 +321,6 @@ uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *co komodoshis = komodo_paxprice(height,base,(char *)"KMD",(uint64_t)fiatoshis); if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 ) { - // put JSON into fiatbuf enough to replicate/validate PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,&fiatoshis); bitcoin_address(destaddr,KOMODO_PUBTYPE,pubkey33,33); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7f4a2e003..1149615f1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -466,7 +466,7 @@ Value sendtoaddress(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } -uint64_t PAX_fiatdest(char *fiatbuf,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); +uint64_t PAX_fiatdest(char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" @@ -484,8 +484,8 @@ Value paxdeposit(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; std::string base = params[2].get_str(); - std::string dest; char fiatbuf[1024]; - komodoshis = PAX_fiatdest(fiatbuf,destaddr,pubkey33,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,(char *)base.c_str(),fiatoshis); + std::string dest; + komodoshis = PAX_fiatdest(destaddr,pubkey33,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,(char *)base.c_str(),fiatoshis); dest.append(destaddr); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) From 30df2e00045e4d2c5122e2c78b6e48153da92d99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:46:20 -0300 Subject: [PATCH 106/205] test --- src/komodo.h | 12 ++++++------ src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 5 ++--- src/komodo_notary.h | 2 +- src/komodo_pax.h | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9b81bcb64..73aa18753 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -23,7 +23,7 @@ #include #include -void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint8_t *opretbuf,uint16_t opretlen); +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen); void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *method,char *params,uint16_t port); @@ -41,7 +41,7 @@ char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "komodo_notary.h" #include "komodo_gateway.h" -void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint8_t *opretbuf,uint16_t opretlen) +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen) { static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; #ifdef WIN32 @@ -161,7 +161,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar fputc('O',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; - if ( fwrite(&value,1,sizeof(value),fp) != sizeof(value) ) + if ( fwrite(&opretvalue,1,sizeof(opretvalue),fp) != sizeof(opretvalue) ) errs++; if ( fwrite(opretbuf,1,opretlen,fp) != opretlen ) errs++; @@ -283,7 +283,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, NOTARIZED_HEIGHT = *notarizedheightp; NOTARIZED_HASH = kmdtxid; NOTARIZED_DESTTXID = desttxid; - komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0); + komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0); } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } #ifdef KOMODO_PAX @@ -349,7 +349,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } if ( i != 0 && notaryid >= 0 && notaryid < 64 && voutmask != 0 ) { - komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0); + komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0,0); //komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); } signedmask = 0; @@ -390,7 +390,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( komodo_isratify(1,numvalid) > 13 ) { memset(&txhash,0,sizeof(txhash)); - komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0); + komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0); } printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height); } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 58b41299b..d46c4eca0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -367,7 +367,7 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) //uint256 zero; //printf("disconnect ht.%d\n",pindex->nHeight); //memset(&zero,0,sizeof(zero)); - //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0,0,0); + //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0,0,0,0); } int32_t komodo_block2height(CBlock *block) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dac5edd7d..56351fe5b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -58,8 +58,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v else { printf("offset.%d opretlen.%d\n",offset,opretlen); - typestr = komodo_opreturn(height,value,&script[offset],opretlen); - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,&script[offset],opretlen); + komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&script[offset],opretlen); } } } @@ -163,7 +162,7 @@ void komodo_gateway_iteration(char *symbol) { fprintf(stderr,"%s.%d ",symbol,KMDHEIGHT); memset(&zero,0,sizeof(zero)); - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,KMDHEIGHT,0,0); + komodo_stateupdate(0,0,0,0,zero,0,0,0,0,KMDHEIGHT,0,0,0); } if ( komodo_gateway_block(symbol,KMDHEIGHT,port) < 0 ) break; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 7b89927c4..c1c24d2b3 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -209,6 +209,6 @@ void komodo_init() } komodo_notarysinit(0,pubkeys,k); memset(&zero,0,sizeof(zero)); - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0); + komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0); } } diff --git a/src/komodo_pax.h b/src/komodo_pax.h index ea8132588..5d73ad053 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -303,7 +303,7 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen) double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; uint256 zero; numpvals = dpow_readprices(pricefeed,×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); memset(&zero,0,sizeof(zero)); - komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0); + komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0,0); printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); } From b55937de6399b003730d74f891bb9a1a2149a517 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:47:36 -0300 Subject: [PATCH 107/205] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 2 +- src/komodo_pax.h | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 73aa18753..b59fcd08c 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -165,7 +165,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(opretbuf,1,opretlen,fp) != opretlen ) errs++; - komodo_opreturn(height,value,opretbuf,opretlen); + komodo_opreturn(height,opretvalue,opretbuf,opretlen); } else if ( notarypubs != 0 && numnotaries > 0 ) { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 56351fe5b..d24afdc81 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -19,7 +19,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) { - uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; if ( opretbuf[0] == 'D' ) { if ( opretlen == 34 ) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 5d73ad053..45ac9123d 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -310,7 +310,6 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen) uint64_t PAX_fiatdest(char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) { uint8_t shortflag = 0; char base[4]; int32_t i; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0; - fiatbuf[0] = 0; if ( strcmp(base,(char *)"KMD") == 0 || strcmp(base,(char *)"kmd") == 0 ) return(0); for (i=0; i<3; i++) From 289dc57bf60e9d6bdd71912a070c537147daa8ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 10:51:41 -0300 Subject: [PATCH 108/205] test --- src/komodo.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b59fcd08c..ec4b8b57a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -109,13 +109,16 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar else if ( func == 'O' ) { uint16_t olen; uint64_t ovalue; uint8_t opret[10000]; - if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) ) - errs++; if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) ) errs++; - if ( fread(opret,1,olen,fp) != olen ) + if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) ) errs++; - komodo_opreturn(ht,ovalue,opret,olen); + if ( olen < sizeof(opret) ) + { + if ( fread(opret,1,olen,fp) != olen ) + errs++; + komodo_opreturn(ht,ovalue,opret,olen); + } else printf("illegal olen.%u\n",olen); } else if ( func == 'D' ) { @@ -158,11 +161,15 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else if ( opretbuf != 0 && opretlen > 0 ) { + uint16_t olen; fputc('O',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; if ( fwrite(&opretvalue,1,sizeof(opretvalue),fp) != sizeof(opretvalue) ) errs++; + olen = opretlen; + if ( fwrite(&olen,1,sizeof(olen),fp) != olen ) + errs++; if ( fwrite(opretbuf,1,opretlen,fp) != opretlen ) errs++; komodo_opreturn(height,opretvalue,opretbuf,opretlen); From 90e4a02cdf6ff8ffa80ff6f320e3e89d8cc60b11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 11:09:05 -0300 Subject: [PATCH 109/205] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d24afdc81..83e5a6902 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -20,6 +20,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + printf("komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); if ( opretbuf[0] == 'D' ) { if ( opretlen == 34 ) From b673d264f4e66b1e4d599844dfcaf62575cfa8a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 11:21:25 -0300 Subject: [PATCH 110/205] test --- src/komodo.h | 8 ++++---- src/komodo_gateway.h | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index ec4b8b57a..9b2c4052f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -124,7 +124,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar { //printf("D[%d]\n",ht); } -#ifdef KOMODO_PAX +//#ifdef KOMODO_PAX else if ( func == 'V' ) { int32_t numpvals; uint32_t pvals[128]; @@ -135,7 +135,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); } else printf("error loading pvals[%d]\n",numpvals); } -#endif +//#endif else printf("illegal func.(%d %c)\n",func,func); } } else fp = fopen(fname,"wb+"); @@ -199,7 +199,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); } -#ifdef KOMODO_PAX +//#ifdef KOMODO_PAX else if ( pvals != 0 && numpvals > 0 ) { fputc('V',fp); @@ -211,7 +211,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_pvals(height,pvals,numpvals); //printf("save pvals height.%d numpvals.%d\n",height,numpvals); } -#endif +//#endif else if ( height != 0 ) { //printf("func N ht.%d errs.%d\n",NOTARIZED_HEIGHT,errs); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 83e5a6902..7652a4657 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -20,6 +20,8 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + if ( opretlen == 72 ) + return("notarized"); printf("komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); if ( opretbuf[0] == 'D' ) { @@ -47,13 +49,13 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v typestr = "unknown"; if ( script[offset++] == 0x6a ) { - if ( len >= 32*2+4 && strcmp((char *)&script[1+32*2+4],"KMD") == 0 ) + offset += komodo_scriptitemlen(&opretlen,&script[offset]); + if ( len >= offset+32*2+4 && strcmp((char *)&script[offset+32*2+4],"KMD") == 0 ) typestr = "notarized"; if ( script[2] == 'P' ) typestr = "pricefeed"; else { - offset += komodo_scriptitemlen(&opretlen,&script[offset]); if ( script[offset] == 'P' ) komodo_paxpricefeed(height,&script[++offset],opretlen); else From 9b9adadc595e8eae45578c36ae6504cef25f3bdd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 11:25:57 -0300 Subject: [PATCH 111/205] test --- src/komodo_gateway.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7652a4657..cfcd49383 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -52,24 +52,22 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v offset += komodo_scriptitemlen(&opretlen,&script[offset]); if ( len >= offset+32*2+4 && strcmp((char *)&script[offset+32*2+4],"KMD") == 0 ) typestr = "notarized"; - if ( script[2] == 'P' ) + else if ( script[offset] == 'P' ) + { typestr = "pricefeed"; + komodo_paxpricefeed(height,&script[++offset],opretlen); + printf("height.%d pricefeed len.%d\n",opretlen); + } else { - if ( script[offset] == 'P' ) - komodo_paxpricefeed(height,&script[++offset],opretlen); - else - { - printf("offset.%d opretlen.%d\n",offset,opretlen); - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&script[offset],opretlen); - } + komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&script[offset],opretlen); + for (i=0; i 13 ) typestr = "ratify"; - for (i=0; i Date: Wed, 26 Oct 2016 11:26:38 -0300 Subject: [PATCH 112/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cfcd49383..8cd180e5b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -56,7 +56,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v { typestr = "pricefeed"; komodo_paxpricefeed(height,&script[++offset],opretlen); - printf("height.%d pricefeed len.%d\n",opretlen); + printf("height.%d pricefeed len.%d\n",height,opretlen); } else { From 9555ab64f89e38fd39f1d723c8b76af25bd7664b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 11:36:21 -0300 Subject: [PATCH 113/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8cd180e5b..663925fac 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -58,7 +58,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v komodo_paxpricefeed(height,&script[++offset],opretlen); printf("height.%d pricefeed len.%d\n",height,opretlen); } - else + else { komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&script[offset],opretlen); for (i=0; i Date: Wed, 26 Oct 2016 11:39:48 -0300 Subject: [PATCH 114/205] test --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 663925fac..0791e0c15 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -58,7 +58,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v komodo_paxpricefeed(height,&script[++offset],opretlen); printf("height.%d pricefeed len.%d\n",height,opretlen); } - else + else { komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&script[offset],opretlen); for (i=0; i Date: Wed, 26 Oct 2016 11:42:14 -0300 Subject: [PATCH 115/205] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0791e0c15..3d73efc9c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -96,6 +96,7 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, else if ( isspecial != 0 && len <= sizeof(script) ) { decode_hex(script,len,hexstr); + if ( len != 74 ) printf("ht.%d txi.%d vout.%d/%d %s script\n",height,txi,vout,n,hexstr); komodo_gateway_voutupdate(symbol,height,txi,vout,n,value,script,len); } From 844a6138ce1778faa995f7e4c30215f7a45acc8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 11:55:17 -0300 Subject: [PATCH 116/205] test --- src/komodo.h | 12 ++++++++---- src/komodo_gateway.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9b2c4052f..c05cfae88 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -230,7 +230,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } } -int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp) +int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value) { static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) @@ -267,7 +267,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, } } } - if ( j == 1 && scriptbuf[len++] == 0x6a ) + if ( scriptbuf[len++] == 0x6a ) { if ( (opretlen= scriptbuf[len++]) == 0x4c ) opretlen = scriptbuf[len++]; @@ -276,7 +276,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, opretlen = scriptbuf[len++]; opretlen = (opretlen << 8) + scriptbuf[len++]; } - if ( opretlen >= 32*2+4 && strcmp(KOMODO_SOURCE,(char *)&scriptbuf[len+32*2+4]) == 0 ) + if ( j == 1 && opretlen >= 32*2+4 && strcmp(KOMODO_SOURCE,(char *)&scriptbuf[len+32*2+4]) == 0 ) { len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); @@ -297,6 +297,10 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, else if ( i == 0 && scriptbuf[len] == 'P' ) komodo_paxpricefeed(height,&scriptbuf[++len],opretlen); #endif + else + { + komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&script[len],opretlen); + } } return(notaryid); } @@ -345,7 +349,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #else memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); #endif - notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight); + notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].value); if ( 0 && i > 0 ) { for (k=0; k> 1; - if ( vout == 0 && memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35 ) + if ( vout == 0 && ((memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35) || (memcmp(&hexstr[6],CRYPTO777_RMD160STR,40) == 0 && len == 25)) ) isspecial = 1; else if ( isspecial != 0 && len <= sizeof(script) ) { From 629e8f37e6a39a28bed353bd1ae2968cd29ac4bc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 11:58:10 -0300 Subject: [PATCH 117/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index c05cfae88..b0eec6b59 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -349,7 +349,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #else memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); #endif - notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].value); + notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue); if ( 0 && i > 0 ) { for (k=0; k Date: Wed, 26 Oct 2016 11:58:43 -0300 Subject: [PATCH 118/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index b0eec6b59..3daf376d0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -299,7 +299,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, #endif else { - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&script[len],opretlen); + komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&scriptbuf[len],opretlen); } } return(notaryid); From 878412dfc81875e22890d8cd864bbb1c56a5b2ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 11:59:45 -0300 Subject: [PATCH 119/205] test --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 18518546f..cc93eac95 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -24,6 +24,7 @@ typedef union _bits256 bits256; #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" +#define CRYPTO777_RMD160STR "f1dce4182fce875748c4986b240ff7d7bc3fffb0" #define KOMODO_PUBTYPE 60 From 795751ec56634fa820f6c3435f3c1871b99c410f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 12:12:38 -0300 Subject: [PATCH 120/205] test --- src/komodo_utils.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index cc93eac95..fd2e5dee0 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -958,9 +958,9 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_ script[offset++] = opretlen; } } else script[offset++] = opretlen; - script[offset] = type; // covered by opretlen - memcpy(&script[offset],opret,opretlen); - return(opretlen + offset); + script[offset++] = type; // covered by opretlen + memcpy(&script[offset],opret,opretlen-1); + return(offset + opretlen - 1); } long _stripwhite(char *buf,int accept) From 9db611fa92579bc503fe3d6b0e2915a0be1659df Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 12:14:54 -0300 Subject: [PATCH 121/205] test --- src/komodo.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 3daf376d0..71209910d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -293,10 +293,8 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0); } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } -#ifdef KOMODO_PAX else if ( i == 0 && scriptbuf[len] == 'P' ) komodo_paxpricefeed(height,&scriptbuf[++len],opretlen); -#endif else { komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&scriptbuf[len],opretlen); From 58085d21bd9f247d16ddc8c2f01c65585914c6ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 12:21:39 -0300 Subject: [PATCH 122/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e70be2ed4..e19986cf6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -91,13 +91,13 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, if ( (hexstr= jstr(sobj,(char *)"hex")) != 0 ) { len = (int32_t)strlen(hexstr) >> 1; + if ( len != 74 ) + printf("ht.%d txi.%d vout.%d/%d %s script\n",height,txi,vout,n,hexstr); if ( vout == 0 && ((memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35) || (memcmp(&hexstr[6],CRYPTO777_RMD160STR,40) == 0 && len == 25)) ) isspecial = 1; else if ( isspecial != 0 && len <= sizeof(script) ) { decode_hex(script,len,hexstr); - if ( len != 74 ) - printf("ht.%d txi.%d vout.%d/%d %s script\n",height,txi,vout,n,hexstr); komodo_gateway_voutupdate(symbol,height,txi,vout,n,value,script,len); } } From 1bf821543e7f38951f8587634ecf01e8901ddcd5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 12:37:55 -0300 Subject: [PATCH 123/205] test --- src/komodo.h | 21 ++++++++++++++------- src/komodo_gateway.h | 2 +- src/komodo_pax.h | 38 ++++++++++++++++++++++---------------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 71209910d..1eda3e237 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -202,13 +202,20 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //#ifdef KOMODO_PAX else if ( pvals != 0 && numpvals > 0 ) { - fputc('V',fp); - if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) - errs++; - fputc(numpvals,fp); - if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals ) - errs++; - komodo_pvals(height,pvals,numpvals); + int32_t nonz = 0; + for (i=0; i<32; i++) + if ( pvals[i] != 0 ) + nonz++; + if ( nonz >= 32 ) + { + fputc('V',fp); + if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) + errs++; + fputc(numpvals,fp); + if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals ) + errs++; + komodo_pvals(height,pvals,numpvals); + } //printf("save pvals height.%d numpvals.%d\n",height,numpvals); } //#endif diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e19986cf6..6f7e2e0e1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -92,7 +92,7 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, { len = (int32_t)strlen(hexstr) >> 1; if ( len != 74 ) - printf("ht.%d txi.%d vout.%d/%d %s script\n",height,txi,vout,n,hexstr); + printf("ht.%d txi.%d vout.%d/%d %s script (%d %d)\n",height,txi,vout,n,hexstr,memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66),memcmp(&hexstr[6],CRYPTO777_RMD160STR,40)); if ( vout == 0 && ((memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35) || (memcmp(&hexstr[6],CRYPTO777_RMD160STR,40) == 0 && len == 25)) ) isspecial = 1; else if ( isspecial != 0 && len <= sizeof(script) ) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 45ac9123d..eaed7d2e6 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -71,7 +71,7 @@ void pax_rank(uint64_t *ranked,uint32_t *pvals) int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,double *BTCUSDp,double *CNYUSDp,uint32_t *pvals) { - uint32_t kmdbtc,btcusd,cnyusd; int32_t i,n,len = 0; + uint32_t kmdbtc,btcusd,cnyusd; int32_t i,n,nonz,len = 0; len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)timestampp); len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&n); len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&kmdbtc); // /= 1000 @@ -80,11 +80,15 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl *KMDBTCp = ((double)kmdbtc / (1000000000. * 1000.)); *BTCUSDp = ((double)btcusd / (1000000000. / 1000.)); *CNYUSDp = ((double)cnyusd / 1000000000.); - for (i=0; i 0 ) { - for (i=0; i<32; i++) - printf("%u ",pvals[i]); - printf("t%u n.%d KMD %f BTC %f CNY %f (%f)\n",timestamp,n,KMDBTC,BTCUSD,CNYUSD,CNYUSD!=0?1./CNYUSD:0); - } - if ( timestamp > time(NULL)-600 ) - { - n = komodo_opreturnscript(opret,'P',data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); if ( 0 && lastcrc != crc32 ) { - for (i=0; i time(NULL)-600 ) + { + n = komodo_opreturnscript(opret,'P',data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); + if ( 0 && lastcrc != crc32 ) + { + for (i=0; i maxsize.%d or data[%d]\n",fsize,maxsize,(int32_t)sizeof(data)); From bfa5b4f2171df3c9239516c855ca34e533e866d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 12:48:34 -0300 Subject: [PATCH 124/205] test --- src/komodo.h | 3 ++- src/komodo_gateway.h | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 1eda3e237..0a9071ae0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -202,7 +202,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //#ifdef KOMODO_PAX else if ( pvals != 0 && numpvals > 0 ) { - int32_t nonz = 0; + int32_t i,nonz = 0; for (i=0; i<32; i++) if ( pvals[i] != 0 ) nonz++; @@ -354,6 +354,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #else memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); #endif + // signedmask is needed here! notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue); if ( 0 && i > 0 ) { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6f7e2e0e1..3e9456ce2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -43,14 +43,14 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 return(typestr); } -void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) +void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) { int32_t i,opretlen,offset = 0; uint256 zero; const char *typestr; typestr = "unknown"; if ( script[offset++] == 0x6a ) { offset += komodo_scriptitemlen(&opretlen,&script[offset]); - if ( len >= offset+32*2+4 && strcmp((char *)&script[offset+32*2+4],"KMD") == 0 ) + if ( isspecial != 0 && len >= offset+32*2+4 && strcmp((char *)&script[offset+32*2+4],"KMD") == 0 ) typestr = "notarized"; else if ( script[offset] == 'P' ) { @@ -58,7 +58,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t v komodo_paxpricefeed(height,&script[++offset],opretlen); printf("height.%d pricefeed len.%d\n",height,opretlen); } - else + else if ( isspecial != 0 ) { komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&script[offset],opretlen); for (i=0; i Date: Wed, 26 Oct 2016 12:53:56 -0300 Subject: [PATCH 125/205] test --- src/komodo.h | 4 ++-- src/komodo_gateway.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0a9071ae0..0b2c9d9f4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -300,8 +300,8 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0); } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } - else if ( i == 0 && scriptbuf[len] == 'P' ) - komodo_paxpricefeed(height,&scriptbuf[++len],opretlen); + else if ( i == 0 && (scriptbuf[len] == 'P' || opretlen == 149) ) + komodo_paxpricefeed(height,&scriptbuf[len + scriptbuf[len] == 'P'],opretlen); else { komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&scriptbuf[len],opretlen); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3e9456ce2..a9d648034 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -52,10 +52,10 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int offset += komodo_scriptitemlen(&opretlen,&script[offset]); if ( isspecial != 0 && len >= offset+32*2+4 && strcmp((char *)&script[offset+32*2+4],"KMD") == 0 ) typestr = "notarized"; - else if ( script[offset] == 'P' ) + else if ( txi == 0 && (scriptbuf[offset] == 'P' || opretlen == 149) ) { typestr = "pricefeed"; - komodo_paxpricefeed(height,&script[++offset],opretlen); + komodo_paxpricefeed(height,&scriptbuf[len + scriptbuf[offset] == 'P'],opretlen); printf("height.%d pricefeed len.%d\n",height,opretlen); } else if ( isspecial != 0 ) From 323862dc26655d8d17c9b691c93121b01f304fc7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 12:54:47 -0300 Subject: [PATCH 126/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a9d648034..3254e012a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -52,10 +52,10 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int offset += komodo_scriptitemlen(&opretlen,&script[offset]); if ( isspecial != 0 && len >= offset+32*2+4 && strcmp((char *)&script[offset+32*2+4],"KMD") == 0 ) typestr = "notarized"; - else if ( txi == 0 && (scriptbuf[offset] == 'P' || opretlen == 149) ) + else if ( txi == 0 && (script[offset] == 'P' || opretlen == 149) ) { typestr = "pricefeed"; - komodo_paxpricefeed(height,&scriptbuf[len + scriptbuf[offset] == 'P'],opretlen); + komodo_paxpricefeed(height,&scriptbuf[len + scriptboffset] == 'P'],opretlen); printf("height.%d pricefeed len.%d\n",height,opretlen); } else if ( isspecial != 0 ) From 027e20f4ae4441aa4903a783be898270e85ac640 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 12:55:41 -0300 Subject: [PATCH 127/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3254e012a..ce84e716c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -55,7 +55,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int else if ( txi == 0 && (script[offset] == 'P' || opretlen == 149) ) { typestr = "pricefeed"; - komodo_paxpricefeed(height,&scriptbuf[len + scriptboffset] == 'P'],opretlen); + komodo_paxpricefeed(height,&scriptbuf[len + script[offset] == 'P'],opretlen); printf("height.%d pricefeed len.%d\n",height,opretlen); } else if ( isspecial != 0 ) From aff7deb27472a382925108ee69cb0cba66bd2e28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 12:56:28 -0300 Subject: [PATCH 128/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ce84e716c..e17bc53f2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -55,7 +55,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int else if ( txi == 0 && (script[offset] == 'P' || opretlen == 149) ) { typestr = "pricefeed"; - komodo_paxpricefeed(height,&scriptbuf[len + script[offset] == 'P'],opretlen); + komodo_paxpricefeed(height,&script[len + script[offset] == 'P'],opretlen); printf("height.%d pricefeed len.%d\n",height,opretlen); } else if ( isspecial != 0 ) From d3b56fcbb3e4699da31f4e76e239175b0524d78f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 12:59:02 -0300 Subject: [PATCH 129/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 0b2c9d9f4..300654a26 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -28,7 +28,7 @@ void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *method,char *params,uint16_t port); -int32_t NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT; +int32_t NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 34000; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; From 7d59e5c9a5be3347e78b3e9a9baa237e9f63f88e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:06:45 -0300 Subject: [PATCH 130/205] test --- src/komodo_gateway.h | 1 + src/komodo_pax.h | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e17bc53f2..2f166d791 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -31,6 +31,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( fiatoshis < 0 ) fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); + memset(base,0,sizeof(base)); checktoshis = PAX_fiatdest(destaddr,pubkey33,coinaddr,height,base,fiatoshis); printf("DEPOSIT %.8f %c%s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); // verify price value for fiatoshis of base diff --git a/src/komodo_pax.h b/src/komodo_pax.h index eaed7d2e6..ef2d5b260 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -74,6 +74,11 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl uint32_t kmdbtc,btcusd,cnyusd; int32_t i,n,nonz,len = 0; len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)timestampp); len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&n); + if ( n != 32 ) + { + printf("dpow_readprices illegal n.%d\n",n); + return(-1); + } len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&kmdbtc); // /= 1000 len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&btcusd); // *= 1000 len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&cnyusd); From 7eca18ee7d7a5094e31d2744af6009f1f2cb8d69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:12:23 -0300 Subject: [PATCH 131/205] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 2 +- src/komodo_pax.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 300654a26..0e1ef6ac4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -300,7 +300,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0); } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } - else if ( i == 0 && (scriptbuf[len] == 'P' || opretlen == 149) ) + else if ( i == 0 && opretlen == 149 ) komodo_paxpricefeed(height,&scriptbuf[len + scriptbuf[len] == 'P'],opretlen); else { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2f166d791..dbbfd7f58 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -53,7 +53,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int offset += komodo_scriptitemlen(&opretlen,&script[offset]); if ( isspecial != 0 && len >= offset+32*2+4 && strcmp((char *)&script[offset+32*2+4],"KMD") == 0 ) typestr = "notarized"; - else if ( txi == 0 && (script[offset] == 'P' || opretlen == 149) ) + else if ( txi == 0 && vout == 1 && opretlen == 149 ) { typestr = "pricefeed"; komodo_paxpricefeed(height,&script[len + script[offset] == 'P'],opretlen); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index ef2d5b260..294f70cfd 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -74,7 +74,7 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl uint32_t kmdbtc,btcusd,cnyusd; int32_t i,n,nonz,len = 0; len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)timestampp); len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&n); - if ( n != 32 ) + if ( n != 35 ) { printf("dpow_readprices illegal n.%d\n",n); return(-1); From e4a19e3aebbe03947abcf21af9ff5ce9b048a8af Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:17:04 -0300 Subject: [PATCH 132/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 0e1ef6ac4..0a9469c0b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -132,7 +132,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals ) { komodo_pvals(ht,pvals,numpvals); - //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); + printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); } else printf("error loading pvals[%d]\n",numpvals); } //#endif From 141a7f166567baffc2df9a2163efc18125ce368a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:18:31 -0300 Subject: [PATCH 133/205] test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dbbfd7f58..98ab3c0ef 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -48,6 +48,9 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int { int32_t i,opretlen,offset = 0; uint256 zero; const char *typestr; typestr = "unknown"; + for (i=0; i 13 ) From ab2d6b7811c73760bc5314cb6841924e7e1cbb63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:19:01 -0300 Subject: [PATCH 134/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 98ab3c0ef..fdfe430ce 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -92,7 +92,7 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, if ( (hexstr= jstr(sobj,(char *)"hex")) != 0 ) { len = (int32_t)strlen(hexstr) >> 1; - if ( len != 74 ) + if ( 0 && len != 74 ) printf("ht.%d txi.%d vout.%d/%d %s script (%d %d)\n",height,txi,vout,n,hexstr,memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66),memcmp(&hexstr[6],CRYPTO777_RMD160STR,40)); if ( vout == 0 && ((memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35) || (memcmp(&hexstr[6],CRYPTO777_RMD160STR,40) == 0 && len == 25)) ) isspecial = 1; From babdc001d12bece77ee49a1acdfcf2ca7043f652 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:23:02 -0300 Subject: [PATCH 135/205] test --- src/komodo.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0a9469c0b..7173d6177 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -283,14 +283,14 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, opretlen = scriptbuf[len++]; opretlen = (opretlen << 8) + scriptbuf[len++]; } + for (k=0; k= 32*2+4 && strcmp(KOMODO_SOURCE,(char *)&scriptbuf[len+32*2+4]) == 0 ) { len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); - for (k=0; k NOTARIZED_HEIGHT && *notarizedheightp < height ) { printf("ht.%d NOTARIZED.%d KMD.%s BTCTXID.%s (%s)\n",height,*notarizedheightp,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); @@ -300,7 +300,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0); } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } - else if ( i == 0 && opretlen == 149 ) + else if ( i == 0 && j == 1 && opretlen == 149 ) komodo_paxpricefeed(height,&scriptbuf[len + scriptbuf[len] == 'P'],opretlen); else { From 0201d1a6724d2a438d037d8ad4f4045b814504a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:32:59 -0300 Subject: [PATCH 136/205] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 11 ++++++----- src/komodo_pax.h | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 7173d6177..808c098c9 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -301,7 +301,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } else if ( i == 0 && j == 1 && opretlen == 149 ) - komodo_paxpricefeed(height,&scriptbuf[len + scriptbuf[len] == 'P'],opretlen); + komodo_paxpricefeed(height,&scriptbuf[len],opretlen); else { komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&scriptbuf[len],opretlen); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index fdfe430ce..c3a2e1be4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -20,8 +20,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; - if ( opretlen == 72 ) - return("notarized"); printf("komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); if ( opretbuf[0] == 'D' ) { @@ -48,9 +46,12 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int { int32_t i,opretlen,offset = 0; uint256 zero; const char *typestr; typestr = "unknown"; - for (i=0; i Date: Wed, 26 Oct 2016 13:33:57 -0300 Subject: [PATCH 137/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c3a2e1be4..5199c24fd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -46,7 +46,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int { int32_t i,opretlen,offset = 0; uint256 zero; const char *typestr; typestr = "unknown"; - if ( i != 0 || vout != 0 ) + if ( txi != 0 || vout != 0 ) { for (i=0; i Date: Wed, 26 Oct 2016 13:40:50 -0300 Subject: [PATCH 138/205] test --- src/komodo_gateway.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5199c24fd..2add8b0e6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -31,7 +31,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 bitcoin_address(coinaddr,addrtype,rmd160,20); memset(base,0,sizeof(base)); checktoshis = PAX_fiatdest(destaddr,pubkey33,coinaddr,height,base,fiatoshis); - printf("DEPOSIT %.8f %c%s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); + for (i=0; i %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); // verify price value for fiatoshis of base for (i=0; i<33; i++) printf("%02x",pubkey33[i]); @@ -60,7 +62,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int else if ( txi == 0 && vout == 1 && opretlen == 149 ) { typestr = "pricefeed"; - komodo_paxpricefeed(height,&script[len + script[offset] == 'P'],opretlen); + komodo_paxpricefeed(height,&script[offset],opretlen); printf("height.%d pricefeed len.%d\n",height,opretlen); } else if ( isspecial != 0 ) From ef7b1ba6314766d5aefc5aad3f1eca914bdae4f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:42:13 -0300 Subject: [PATCH 139/205] test --- src/komodo_pax.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 7410ceb93..3a11a7407 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -95,7 +95,10 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl //printf("%u ",pvals[i]); } if ( nonz < n-3 ) + { + printf("nonz.%d n.%d retval -1\n",nonz,n); return(-1); + } pvals[i++] = kmdbtc; pvals[i++] = btcusd; pvals[i++] = cnyusd; From 05c80150740941ff75072797469600bc2470bddf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:48:48 -0300 Subject: [PATCH 140/205] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 83a79835a..65ea0c0a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -726,7 +726,7 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) } else if (!txin.IsFinal()) { - printf("non-final txin seq.%x\n",txin.nSequence); + printf("non-final txin seq.%x locktime.%u vs nTime.%u\n",txin.nSequence,(uint32_t)tx.nLockTime,(uint32_t)nBlockTime); return false; } } From 7127dc4e1d54d79f7a797b9128e305cc3601507e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 13:49:58 -0300 Subject: [PATCH 141/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2add8b0e6..fb0fe98df 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -48,11 +48,11 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int { int32_t i,opretlen,offset = 0; uint256 zero; const char *typestr; typestr = "unknown"; - if ( txi != 0 || vout != 0 ) + //if ( txi != 0 || vout != 0 ) { for (i=0; i Date: Wed, 26 Oct 2016 13:53:45 -0300 Subject: [PATCH 142/205] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index fb0fe98df..f9872cdc2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -165,6 +165,7 @@ void komodo_gateway_iteration(char *symbol) { for (i=0; i<1000 && KMDHEIGHT Date: Wed, 26 Oct 2016 13:55:59 -0300 Subject: [PATCH 143/205] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 65ea0c0a3..e5fcc4736 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -720,7 +720,7 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) } BOOST_FOREACH(const CTxIn& txin, tx.vin) { - if ( txin.nSequence == 0xfffffffe && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD && (int64_t)tx.nLockTime > nBlockTime ) + if ( txin.nSequence == 0xfffffffe && (((int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD && (int64_t)tx.nLockTime > nBlockTime) || ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD && (int64_t)tx.nLockTime > nBlockHeight)) ) { } From bda0b3bd2a5b82da5b86a6a4cf18e39cf0716490 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 14:12:45 -0300 Subject: [PATCH 144/205] test --- src/komodo_pax.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 3a11a7407..b6088a80a 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -91,6 +91,8 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl { if ( pvals[i] != 0 ) nonz++; + else if ( nonz != 0 ) + printf("pvals[%d] is zero\n",i); len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&pvals[i]); //printf("%u ",pvals[i]); } From 1ac1cda04c481c976989d5eb102d505adbe4991c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 14:15:25 -0300 Subject: [PATCH 145/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 808c098c9..740fac6fd 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -57,7 +57,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar { if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; - //printf("func.(%d %c) ht.%d\n",func,func,ht); + printf("func.(%d %c) ht.%d\n",func,func,ht); if ( func == 'P' ) { if ( (num= fgetc(fp)) < 64 ) From 49df008c16e791379926c789e2006ce718cdba89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 14:50:59 -0300 Subject: [PATCH 146/205] test --- src/komodo.h | 7 ++++++- src/komodo_pax.h | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 740fac6fd..44119923c 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -57,7 +57,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar { if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; - printf("func.(%d %c) ht.%d\n",func,func,ht); + //printf("func.(%d %c) ht.%d\n",func,func,ht); if ( func == 'P' ) { if ( (num= fgetc(fp)) < 64 ) @@ -141,6 +141,11 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else fp = fopen(fname,"wb+"); printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); } + if ( height <= 0 ) + { + printf("early return: stateupdate height.%d\n",height); + return; + } if ( fp != 0 ) // write out funcid, height, other fields, call side effect function { if ( height < 0 ) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index b6088a80a..46a2b37d4 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -91,14 +91,14 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl { if ( pvals[i] != 0 ) nonz++; - else if ( nonz != 0 ) - printf("pvals[%d] is zero\n",i); + //else if ( nonz != 0 ) + // printf("pvals[%d] is zero\n",i); len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&pvals[i]); //printf("%u ",pvals[i]); } if ( nonz < n-3 ) { - printf("nonz.%d n.%d retval -1\n",nonz,n); + //printf("nonz.%d n.%d retval -1\n",nonz,n); return(-1); } pvals[i++] = kmdbtc; From ccf3a606ef83a810a5edafb77d8b7f557db2da33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 14:59:26 -0300 Subject: [PATCH 147/205] test --- src/komodo.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 44119923c..0a7885401 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -106,7 +106,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar printf("KMDHEIGHT <- %d\n",kheight); } } - else if ( func == 'O' ) + /*else if ( func == 'O' ) { uint16_t olen; uint64_t ovalue; uint8_t opret[10000]; if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) ) @@ -119,7 +119,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; komodo_opreturn(ht,ovalue,opret,olen); } else printf("illegal olen.%u\n",olen); - } + }*/ else if ( func == 'D' ) { //printf("D[%d]\n",ht); @@ -164,7 +164,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) errs++; } - else if ( opretbuf != 0 && opretlen > 0 ) + /*else if ( opretbuf != 0 && opretlen > 0 ) { uint16_t olen; fputc('O',fp); @@ -178,7 +178,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(opretbuf,1,opretlen,fp) != opretlen ) errs++; komodo_opreturn(height,opretvalue,opretbuf,opretlen); - } + }*/ else if ( notarypubs != 0 && numnotaries > 0 ) { //printf("func P[%d] errs.%d\n",numnotaries,errs); From 01f9cb3d1ddc4ba226359872084a69f2dbe9bcd3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 15:17:39 -0300 Subject: [PATCH 148/205] test --- src/komodo.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0a7885401..594e11934 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -28,7 +28,7 @@ void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *method,char *params,uint16_t port); -int32_t NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 34000; +int32_t NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 40000; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; @@ -41,6 +41,7 @@ char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "komodo_notary.h" #include "komodo_gateway.h" + void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen) { static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; @@ -106,7 +107,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar printf("KMDHEIGHT <- %d\n",kheight); } } - /*else if ( func == 'O' ) + else if ( func == 'R' ) { uint16_t olen; uint64_t ovalue; uint8_t opret[10000]; if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) ) @@ -119,7 +120,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; komodo_opreturn(ht,ovalue,opret,olen); } else printf("illegal olen.%u\n",olen); - }*/ + } else if ( func == 'D' ) { //printf("D[%d]\n",ht); @@ -164,21 +165,20 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) errs++; } - /*else if ( opretbuf != 0 && opretlen > 0 ) + else if ( opretbuf != 0 && opretlen > 0 ) { - uint16_t olen; - fputc('O',fp); + uint16_t olen = opretlen; + fputc('R',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; if ( fwrite(&opretvalue,1,sizeof(opretvalue),fp) != sizeof(opretvalue) ) errs++; - olen = opretlen; if ( fwrite(&olen,1,sizeof(olen),fp) != olen ) errs++; - if ( fwrite(opretbuf,1,opretlen,fp) != opretlen ) + if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; - komodo_opreturn(height,opretvalue,opretbuf,opretlen); - }*/ + komodo_opreturn(height,opretvalue,opretbuf,olen); + } else if ( notarypubs != 0 && numnotaries > 0 ) { //printf("func P[%d] errs.%d\n",numnotaries,errs); From 61d40e34ee83d1fe326cdfe017bfb9caede28a05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 15:28:24 -0300 Subject: [PATCH 149/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 594e11934..854fbbde7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -309,7 +309,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, komodo_paxpricefeed(height,&scriptbuf[len],opretlen); else { - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&scriptbuf[len],opretlen); + komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,value,&scriptbuf[len],opretlen); } } return(notaryid); From d6ce6f1657e1c3b4cbfe5ad0ae0ad25b00711021 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 15:29:44 -0300 Subject: [PATCH 150/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f9872cdc2..f6e762d04 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -67,7 +67,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int } else if ( isspecial != 0 ) { - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,value,&script[offset],opretlen); + komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,value,&script[offset],opretlen); } } else if ( numvouts > 13 ) @@ -170,7 +170,7 @@ void komodo_gateway_iteration(char *symbol) { fprintf(stderr,"%s.%d ",symbol,KMDHEIGHT); memset(&zero,0,sizeof(zero)); - komodo_stateupdate(0,0,0,0,zero,0,0,0,0,KMDHEIGHT,0,0,0); + komodo_stateupdate(KMDHEIGHT,0,0,0,zero,0,0,0,0,KMDHEIGHT,0,0,0); } if ( komodo_gateway_block(symbol,KMDHEIGHT,port) < 0 ) break; From d95bcb64858f52ac5e272c5b62686ef2c89cc7aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 16:02:50 -0300 Subject: [PATCH 151/205] test --- src/komodo.h | 19 ++++++++++--------- src/komodo_gateway.h | 7 +++++-- src/komodo_pax.h | 2 +- src/wallet/rpcwallet.cpp | 10 ++-------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 854fbbde7..e487bf73d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -58,7 +58,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar { if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; - //printf("func.(%d %c) ht.%d\n",func,func,ht); + printf("fpos.%ld func.(%d %c) ht.%d\n",ftell(fp),func,func,ht); if ( func == 'P' ) { if ( (num= fgetc(fp)) < 64 ) @@ -149,10 +149,11 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } if ( fp != 0 ) // write out funcid, height, other fields, call side effect function { + printf("fpos.%ld ",ftell(fp)); if ( height < 0 ) { height = -height; - //printf("func D[%d] errs.%d\n",height,errs); + printf("func D[%d] errs.%d\n",height,errs); fputc('D',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; @@ -164,6 +165,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) errs++; + printf("ht.%d K %d\n",height,KMDheight); } else if ( opretbuf != 0 && opretlen > 0 ) { @@ -177,11 +179,12 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; + printf("ht.%d R opret[%d]\n",height,olen); komodo_opreturn(height,opretvalue,opretbuf,olen); } else if ( notarypubs != 0 && numnotaries > 0 ) { - //printf("func P[%d] errs.%d\n",numnotaries,errs); + printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs); fputc('P',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; @@ -192,7 +195,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else if ( voutmask != 0 && numvouts > 0 ) { - //printf("func U %d %d errs.%d hashsize.%ld\n",numvouts,notaryid,errs,sizeof(txhash)); + printf("ht.%d func U %d %d errs.%d hashsize.%ld\n",height,numvouts,notaryid,errs,sizeof(txhash)); fputc('U',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; @@ -220,13 +223,14 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals ) errs++; komodo_pvals(height,pvals,numpvals); + printf("ht.%d V numpvals[%d]\n",height,numpvals); } //printf("save pvals height.%d numpvals.%d\n",height,numpvals); } //#endif else if ( height != 0 ) { - //printf("func N ht.%d errs.%d\n",NOTARIZED_HEIGHT,errs); + printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; @@ -307,10 +311,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, } else if ( i == 0 && j == 1 && opretlen == 149 ) komodo_paxpricefeed(height,&scriptbuf[len],opretlen); - else - { - komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,value,&scriptbuf[len],opretlen); - } + else komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,value,&scriptbuf[len],opretlen); } return(notaryid); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f6e762d04..35a6a2869 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -19,18 +19,21 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) { - uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; printf("komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); if ( opretbuf[0] == 'D' ) { if ( opretlen == 34 ) { +#ifdef KOMODO_ISSUER + tokomodo = 1; +#endif PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&fiatoshis); if ( fiatoshis < 0 ) fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); memset(base,0,sizeof(base)); - checktoshis = PAX_fiatdest(destaddr,pubkey33,coinaddr,height,base,fiatoshis); + checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis); for (i=0; i %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 46a2b37d4..319ebe722 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -325,7 +325,7 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen) printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); } -uint64_t PAX_fiatdest(char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) +uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) { uint8_t shortflag = 0; char base[4]; int32_t i; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0; if ( strcmp(base,(char *)"KMD") == 0 || strcmp(base,(char *)"kmd") == 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1149615f1..e245fad37 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -466,7 +466,7 @@ Value sendtoaddress(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } -uint64_t PAX_fiatdest(char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); +uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" @@ -485,7 +485,7 @@ Value paxdeposit(const Array& params, bool fHelp) int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; std::string base = params[2].get_str(); std::string dest; - komodoshis = PAX_fiatdest(destaddr,pubkey33,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,(char *)base.c_str(),fiatoshis); + komodoshis = PAX_fiatdest(0,destaddr,pubkey33,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,(char *)base.c_str(),fiatoshis); dest.append(destaddr); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) @@ -496,12 +496,6 @@ Value paxdeposit(const Array& params, bool fHelp) printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",chainActive.Tip()->nHeight,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis); EnsureWalletIsUnlocked(); CWalletTx wtx; - /*std::string account,paxstr,tmp; - account.append((char *)"account"); - paxstr.append(fiatbuf); - tmp.append("PAX"); - wtx.mapValue["PAX"] = paxstr; - pwalletMain->SetAddressBook(destaddress.Get(),account,tmp);*/ uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000; if ( fee < 10000 ) fee = 10000; From 7c6f82982597b944bd75048fe75885510789a934 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 16:18:09 -0300 Subject: [PATCH 152/205] test --- src/komodo.h | 8 ++++---- src/komodo_pax.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e487bf73d..28930cdc7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -58,7 +58,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar { if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; - printf("fpos.%ld func.(%d %c) ht.%d\n",ftell(fp),func,func,ht); + printf("fpos.%ld func.(%d %c) ht.%d ",ftell(fp),func,func,ht); if ( func == 'P' ) { if ( (num= fgetc(fp)) < 64 ) @@ -71,7 +71,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_notarysinit(ht,pubkeys,num); } } else printf("illegal num.%d\n",num); - //printf("P[%d]\n",num); + printf("P[%d]\n",num); } else if ( func == 'N' ) { @@ -89,7 +89,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar uint8_t n,nid; uint256 hash; uint64_t mask; n = fgetc(fp); nid = fgetc(fp); - //printf("U %d %d\n",n,nid); + printf("U %d %d\n",n,nid); if ( fread(&mask,1,sizeof(mask),fp) != sizeof(mask) ) errs++; if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) ) @@ -104,8 +104,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( kheight > KMDHEIGHT ) { KMDHEIGHT = kheight; - printf("KMDHEIGHT <- %d\n",kheight); } + printf("ht.%d KMDHEIGHT <- %d\n",ht,kheight); } else if ( func == 'R' ) { diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 319ebe722..92ba3f8d9 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -327,8 +327,8 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen) uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) { - uint8_t shortflag = 0; char base[4]; int32_t i; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0; - if ( strcmp(base,(char *)"KMD") == 0 || strcmp(base,(char *)"kmd") == 0 ) + uint8_t shortflag = 0; char base[4]; int32_t i,baseid; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0; + if ( (baseid= komodo_baseid(origbase)) < 0 || baseid == MAX_CURRENCIES ) return(0); for (i=0; i<3; i++) base[i] = toupper(origbase[i]); @@ -338,7 +338,7 @@ uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char komodoshis = komodo_paxprice(height,base,(char *)"KMD",(uint64_t)fiatoshis); if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 ) { - PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,&fiatoshis); + PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,tokomodo != 0 ? &komodoshis : &fiatoshis); bitcoin_address(destaddr,KOMODO_PUBTYPE,pubkey33,33); } return(komodoshis); From fe965b1c89076ead6ce739d0c479af94e5decf49 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 16:20:00 -0300 Subject: [PATCH 153/205] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 92ba3f8d9..166c58c51 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -327,7 +327,7 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen) uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) { - uint8_t shortflag = 0; char base[4]; int32_t i,baseid; uint8_t addrtype,rmd160[20]; uint64_t komodoshis = 0; + uint8_t shortflag = 0; char base[4]; int32_t i,baseid; uint8_t addrtype,rmd160[20]; int64_t komodoshis = 0; if ( (baseid= komodo_baseid(origbase)) < 0 || baseid == MAX_CURRENCIES ) return(0); for (i=0; i<3; i++) From 32f7d3943ec72b67844d781b89c67cda1ac3ecd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 16:33:23 -0300 Subject: [PATCH 154/205] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 166c58c51..901498835 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -96,11 +96,11 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&pvals[i]); //printf("%u ",pvals[i]); } - if ( nonz < n-3 ) + /*if ( nonz < n-3 ) { //printf("nonz.%d n.%d retval -1\n",nonz,n); return(-1); - } + }*/ pvals[i++] = kmdbtc; pvals[i++] = btcusd; pvals[i++] = cnyusd; From 2578b002665508c6ba27cb92d22f57e2ffeda595 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 17:02:33 -0300 Subject: [PATCH 155/205] test --- src/komodo.h | 25 +++++++++++++------------ src/komodo_gateway.h | 10 +++++++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 28930cdc7..f6bebe85b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -32,6 +32,7 @@ int32_t NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 40000; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; +uint64_t KOMODO_DEPOSIT; uint8_t KOMODO_SCRIPTPUBKEY[25]; #include "komodo_utils.h" #include "cJSON.c" @@ -58,7 +59,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar { if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; - printf("fpos.%ld func.(%d %c) ht.%d ",ftell(fp),func,func,ht); + //printf("fpos.%ld func.(%d %c) ht.%d ",ftell(fp),func,func,ht); if ( func == 'P' ) { if ( (num= fgetc(fp)) < 64 ) @@ -71,7 +72,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_notarysinit(ht,pubkeys,num); } } else printf("illegal num.%d\n",num); - printf("P[%d]\n",num); + //printf("P[%d]\n",num); } else if ( func == 'N' ) { @@ -89,7 +90,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar uint8_t n,nid; uint256 hash; uint64_t mask; n = fgetc(fp); nid = fgetc(fp); - printf("U %d %d\n",n,nid); + //printf("U %d %d\n",n,nid); if ( fread(&mask,1,sizeof(mask),fp) != sizeof(mask) ) errs++; if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) ) @@ -105,7 +106,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar { KMDHEIGHT = kheight; } - printf("ht.%d KMDHEIGHT <- %d\n",ht,kheight); + //printf("ht.%d KMDHEIGHT <- %d\n",ht,kheight); } else if ( func == 'R' ) { @@ -149,11 +150,11 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } if ( fp != 0 ) // write out funcid, height, other fields, call side effect function { - printf("fpos.%ld ",ftell(fp)); + //printf("fpos.%ld ",ftell(fp)); if ( height < 0 ) { height = -height; - printf("func D[%d] errs.%d\n",height,errs); + //printf("func D[%d] errs.%d\n",height,errs); fputc('D',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; @@ -165,7 +166,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) errs++; - printf("ht.%d K %d\n",height,KMDheight); + //printf("ht.%d K %d\n",height,KMDheight); } else if ( opretbuf != 0 && opretlen > 0 ) { @@ -179,12 +180,12 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; - printf("ht.%d R opret[%d]\n",height,olen); + //printf("ht.%d R opret[%d]\n",height,olen); komodo_opreturn(height,opretvalue,opretbuf,olen); } else if ( notarypubs != 0 && numnotaries > 0 ) { - printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs); + //printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs); fputc('P',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; @@ -195,7 +196,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else if ( voutmask != 0 && numvouts > 0 ) { - printf("ht.%d func U %d %d errs.%d hashsize.%ld\n",height,numvouts,notaryid,errs,sizeof(txhash)); + //printf("ht.%d func U %d %d errs.%d hashsize.%ld\n",height,numvouts,notaryid,errs,sizeof(txhash)); fputc('U',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; @@ -223,14 +224,14 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals ) errs++; komodo_pvals(height,pvals,numpvals); - printf("ht.%d V numpvals[%d]\n",height,numpvals); + //printf("ht.%d V numpvals[%d]\n",height,numpvals); } //printf("save pvals height.%d numpvals.%d\n",height,numpvals); } //#endif else if ( height != 0 ) { - printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); + //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 35a6a2869..b1b5dc02b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -15,7 +15,6 @@ // convert paxdeposit into new coins in the next block // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse -// need to save most processed block in other chain(s) const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) { @@ -42,6 +41,15 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf("%02x",pubkey33[i]); printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); typestr = "deposit"; +#ifdef KOMODO_ISSUER + KOMODO_DEPOSIT = fiatoshis; + KOMODO_SCRIPTPUBKEY[0] = 0x76; + KOMODO_SCRIPTPUBKEY[1] = 0xa9; + KOMODO_SCRIPTPUBKEY[2] = 0x14; + memcpy(&KOMODO_SCRIPTPUBKEY[3],rmd160,0x14); + KOMODO_SCRIPTPUBKEY[23] = 0x88; + KOMODO_SCRIPTPUBKEY[24] = 0xac; +#endif } } return(typestr); From 3b145e31b110e5f9b6f1465ef255da5d3e5107bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 17:13:38 -0300 Subject: [PATCH 156/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b1b5dc02b..70227009b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -59,7 +59,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int { int32_t i,opretlen,offset = 0; uint256 zero; const char *typestr; typestr = "unknown"; - //if ( txi != 0 || vout != 0 ) + if ( txi != 0 || vout != 0 ) { for (i=0; i Date: Wed, 26 Oct 2016 17:19:06 -0300 Subject: [PATCH 157/205] test --- src/komodo_pax.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 901498835..d78324f34 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -185,7 +185,9 @@ int32_t PAX_pubkey(int32_t rwflag,uint8_t *pubkey33,uint8_t *addrtypep,uint8_t r else { *shortflagp = (pubkey33[0] == 0x03); - memcpy(fiat,&pubkey33[1],4); + memcpy(fiat,&pubkey33[1],3); + printf("%02x %02x %02x\n",fiat[0],fiat[1],fiat[2]); + fiat[3] = 0; iguana_rwnum(rwflag,&pubkey33[4],sizeof(*fiatoshisp),(void *)fiatoshisp); if ( *shortflagp != 0 ) *fiatoshisp = -(*fiatoshisp); From 552bdf22f50e26f611379b109e95c98d51bdc48e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 17:25:29 -0300 Subject: [PATCH 158/205] test --- src/komodo_gateway.h | 9 +++++---- src/komodo_pax.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 70227009b..e56977a47 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -19,7 +19,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; - printf("komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); + //printf("komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); if ( opretbuf[0] == 'D' ) { if ( opretlen == 34 ) @@ -27,11 +27,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 #ifdef KOMODO_ISSUER tokomodo = 1; #endif + memset(base,0,sizeof(base)); PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&fiatoshis); if ( fiatoshis < 0 ) fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); - memset(base,0,sizeof(base)); checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis); for (i=0; i Date: Wed, 26 Oct 2016 17:28:52 -0300 Subject: [PATCH 159/205] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index f6bebe85b..92d905cbe 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -134,7 +134,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals ) { komodo_pvals(ht,pvals,numpvals); - printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); + //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); } else printf("error loading pvals[%d]\n",numpvals); } //#endif diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e56977a47..2bc0a14d4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -42,14 +42,17 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); typestr = "deposit"; #ifdef KOMODO_ISSUER - printf("START MINER!\n"); - KOMODO_DEPOSIT = fiatoshis; - KOMODO_SCRIPTPUBKEY[0] = 0x76; - KOMODO_SCRIPTPUBKEY[1] = 0xa9; - KOMODO_SCRIPTPUBKEY[2] = 0x14; - memcpy(&KOMODO_SCRIPTPUBKEY[3],rmd160,0x14); - KOMODO_SCRIPTPUBKEY[23] = 0x88; - KOMODO_SCRIPTPUBKEY[24] = 0xac; + if ( strncmp(KOMODO_SYMBOL,base,strlen(base)) == 0 ) + { + printf("START %s MINER!\n",KOMODO_SYMBOL); + KOMODO_DEPOSIT = fiatoshis; + KOMODO_SCRIPTPUBKEY[0] = 0x76; + KOMODO_SCRIPTPUBKEY[1] = 0xa9; + KOMODO_SCRIPTPUBKEY[2] = 0x14; + memcpy(&KOMODO_SCRIPTPUBKEY[3],rmd160,0x14); + KOMODO_SCRIPTPUBKEY[23] = 0x88; + KOMODO_SCRIPTPUBKEY[24] = 0xac; + } #endif } } From 8c0fd042e9536b6293eef3e38b4408d7290586f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 17:30:36 -0300 Subject: [PATCH 160/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2bc0a14d4..90b82892b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -42,9 +42,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); typestr = "deposit"; #ifdef KOMODO_ISSUER - if ( strncmp(KOMODO_SYMBOL,base,strlen(base)) == 0 ) + if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 ) { - printf("START %s MINER!\n",KOMODO_SYMBOL); + printf("START %s MINER!\n",KOMODO_SOURCE); KOMODO_DEPOSIT = fiatoshis; KOMODO_SCRIPTPUBKEY[0] = 0x76; KOMODO_SCRIPTPUBKEY[1] = 0xa9; From 0765bc71cf35db1b160f3590e0e307eda5a52e85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 17:33:45 -0300 Subject: [PATCH 161/205] test --- src/komodo_gateway.h | 2 +- src/komodo_pax.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 90b82892b..cb7db1311 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -78,7 +78,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int { typestr = "pricefeed"; komodo_paxpricefeed(height,&script[offset],opretlen); - printf("height.%d pricefeed len.%d\n",height,opretlen); + //printf("height.%d pricefeed len.%d\n",height,opretlen); } else { diff --git a/src/komodo_pax.h b/src/komodo_pax.h index b96a54be7..75ccf2b36 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -324,7 +324,7 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen) numpvals = dpow_readprices(pricefeed,×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); memset(&zero,0,sizeof(zero)); komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0,0); - printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); + //printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); } uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis) From 6711ddbff77e2531fa9f173793c4f0e6b9ee1150 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 17:40:56 -0300 Subject: [PATCH 162/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 92d905cbe..42cad2481 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -295,7 +295,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, } for (k=0; k= 32*2+4 && strcmp(KOMODO_SOURCE,(char *)&scriptbuf[len+32*2+4]) == 0 ) { len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); From 2d6fb81efd8e495e256534172f10c8cdc1a1eba7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 17:47:08 -0300 Subject: [PATCH 163/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cb7db1311..c7c52c4bc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -42,7 +42,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); typestr = "deposit"; #ifdef KOMODO_ISSUER - if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 ) + if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 && value >= checktoshis*.9999 ) { printf("START %s MINER!\n",KOMODO_SOURCE); KOMODO_DEPOSIT = fiatoshis; From 420d7311e852df67fdec0672b4d1f6f614a3baae Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 19:55:03 -0300 Subject: [PATCH 164/205] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 15 ++++++++------- src/main.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 42cad2481..d4b6932ce 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -328,7 +328,7 @@ int32_t komodo_isratify(int32_t isspecial,int32_t numvalid) // with more than 13 pay2pubkey outputs -> ratify // if all outputs to notary -> notary utxo // if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed -// OP_RETURN: 'D' -> deposit +// OP_RETURN: 'D' -> deposit, 'W' -> withdraw void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c7c52c4bc..22e0c315f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -13,20 +13,21 @@ * * ******************************************************************************/ -// convert paxdeposit into new coins in the next block +// create list of approved deposits, validate all deposits against this list, prevent double deposit +// need to tag deposits with OP_RETURN, ie link with originating txid/vout // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; //printf("komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); - if ( opretbuf[0] == 'D' ) +#ifdef KOMODO_ISSUER + tokomodo = 1; +#endif + if ( opretbuf[0] == ((tokomodo != 0) ? 'D' : 'W') ) { if ( opretlen == 34 ) { -#ifdef KOMODO_ISSUER - tokomodo = 1; -#endif memset(base,0,sizeof(base)); PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&fiatoshis); if ( fiatoshis < 0 ) @@ -42,9 +43,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); typestr = "deposit"; #ifdef KOMODO_ISSUER - if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 && value >= checktoshis*.9999 ) + if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 && ((tokomodo == 0 && value >= checktoshis*.9999) || (tokomodo != 0 && value <= checktoshis/.9999)) ) { - printf("START %s MINER!\n",KOMODO_SOURCE); + printf("START %s MINER! %.8f\n",KOMODO_SOURCE,dstr(fiatoshis)); KOMODO_DEPOSIT = fiatoshis; KOMODO_SCRIPTPUBKEY[0] = 0x76; KOMODO_SCRIPTPUBKEY[1] = 0xa9; diff --git a/src/main.cpp b/src/main.cpp index e5fcc4736..28393810f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1415,8 +1415,8 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) CAmount nSubsidy = 3 * COIN; if ( nHeight == 1 ) return(100000000 * COIN); // ICO allocation - else if ( komodo_moneysupply(nHeight) < MAX_MONEY ) - return(3 * COIN); + //else if ( komodo_moneysupply(nHeight) < MAX_MONEY ) + // return(3 * COIN); else return(0); /* // Mining slow start diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e245fad37..e934bfa66 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -500,7 +500,7 @@ Value paxdeposit(const Array& params, bool fHelp) if ( fee < 10000 ) fee = 10000; opretlen = komodo_opreturnscript(opretbuf,'D',pubkey33,33); - SendMoney(destaddress.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,komodoshis); + SendMoney(address.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,komodoshis); return wtx.GetHash().GetHex(); } From fd15558449c2c76c7179d1c3d777cfa9fa2bdfeb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 26 Oct 2016 20:16:18 -0300 Subject: [PATCH 165/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 22e0c315f..7a4558139 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -181,7 +181,7 @@ void komodo_gateway_iteration(char *symbol) { for (i=0; i<1000 && KMDHEIGHT Date: Wed, 26 Oct 2016 20:49:16 -0300 Subject: [PATCH 166/205] test --- src/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e1fb6aec4..8710f96f8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2933,7 +2933,7 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool) if (!HaveKey(keypool.vchPubKey.GetID())) throw runtime_error("ReserveKeyFromKeyPool(): unknown key in key pool"); assert(keypool.vchPubKey.IsValid()); - LogPrintf("keypool reserve %d\n", nIndex); + //LogPrintf("keypool reserve %d\n", nIndex); } } @@ -2955,7 +2955,7 @@ void CWallet::ReturnKey(int64_t nIndex) LOCK(cs_wallet); setKeyPool.insert(nIndex); } - LogPrintf("keypool return %d\n", nIndex); + //LogPrintf("keypool return %d\n", nIndex); } bool CWallet::GetKeyFromPool(CPubKey& result) From 67e526485da3041cfe08cf960e595c7564c6425b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 06:48:34 -0300 Subject: [PATCH 167/205] test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 28393810f..e5fcc4736 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1415,8 +1415,8 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) CAmount nSubsidy = 3 * COIN; if ( nHeight == 1 ) return(100000000 * COIN); // ICO allocation - //else if ( komodo_moneysupply(nHeight) < MAX_MONEY ) - // return(3 * COIN); + else if ( komodo_moneysupply(nHeight) < MAX_MONEY ) + return(3 * COIN); else return(0); /* // Mining slow start From 429dabb503382ce119b6a7eeda9266c882e11013 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 09:49:42 -0300 Subject: [PATCH 168/205] test --- src/komodo.h | 38 +++++++---- src/komodo_gateway.h | 151 +++++++++++++++++++++++++++++++++++------- src/komodo_notary.h | 2 +- src/komodo_pax.h | 3 +- src/komodo_utils.h | 117 +++++++++++++++++++++++++++++++- src/tinyformat.h | 2 +- src/wallet/wallet.cpp | 3 +- 7 files changed, 272 insertions(+), 44 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d4b6932ce..3e0e43a44 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -23,18 +23,20 @@ #include #include -void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen); +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout); void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *method,char *params,uint16_t port); -int32_t NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 40000; +int32_t ASSETCHAINS_SHORTFLAG,NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 40000; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; -uint64_t KOMODO_DEPOSIT; uint8_t KOMODO_SCRIPTPUBKEY[25]; +uint64_t KOMODO_DEPOSIT,PENDING_KOMODO_TX; #include "komodo_utils.h" +queue_t DepositsQ,PendingsQ; + #include "cJSON.c" #include "komodo_bitcoind.h" #include "komodo_interest.h" @@ -43,7 +45,7 @@ uint64_t KOMODO_DEPOSIT; uint8_t KOMODO_SCRIPTPUBKEY[25]; #include "komodo_gateway.h" -void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen) +void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; #ifdef WIN32 @@ -110,7 +112,11 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else if ( func == 'R' ) { - uint16_t olen; uint64_t ovalue; uint8_t opret[10000]; + uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[10000]; + if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) ) + errs++; + if ( fread(&v,1,sizeof(v),fp) != sizeof(v) ) + errs++; if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) ) errs++; if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) ) @@ -119,7 +125,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar { if ( fread(opret,1,olen,fp) != olen ) errs++; - komodo_opreturn(ht,ovalue,opret,olen); + komodo_opreturn(ht,ovalue,opret,olen,txid,v); } else printf("illegal olen.%u\n",olen); } else if ( func == 'D' ) @@ -174,6 +180,10 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar fputc('R',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; + if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) ) + errs++; + if ( fwrite(&vout,1,sizeof(vout),fp) != sizeof(vout) ) + errs++; if ( fwrite(&opretvalue,1,sizeof(opretvalue),fp) != sizeof(opretvalue) ) errs++; if ( fwrite(&olen,1,sizeof(olen),fp) != olen ) @@ -181,7 +191,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; //printf("ht.%d R opret[%d]\n",height,olen); - komodo_opreturn(height,opretvalue,opretbuf,olen); + komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,numvouts); } else if ( notarypubs != 0 && numnotaries > 0 ) { @@ -293,9 +303,9 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, opretlen = scriptbuf[len++]; opretlen = (opretlen << 8) + scriptbuf[len++]; } - for (k=0; k= 32*2+4 && strcmp(KOMODO_SOURCE,(char *)&scriptbuf[len+32*2+4]) == 0 ) { len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); @@ -307,12 +317,12 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, NOTARIZED_HEIGHT = *notarizedheightp; NOTARIZED_HASH = kmdtxid; NOTARIZED_DESTTXID = desttxid; - komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0); + komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0); } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } else if ( i == 0 && j == 1 && opretlen == 149 ) komodo_paxpricefeed(height,&scriptbuf[len],opretlen); - else komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,value,&scriptbuf[len],opretlen); + else komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,value,&scriptbuf[len],opretlen,j); } return(notaryid); } @@ -373,7 +383,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } if ( i != 0 && notaryid >= 0 && notaryid < 64 && voutmask != 0 ) { - komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0,0); + komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0,0,0); //komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); } signedmask = 0; @@ -414,7 +424,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( komodo_isratify(1,numvalid) > 13 ) { memset(&txhash,0,sizeof(txhash)); - komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0); + komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0); } printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7a4558139..c6386d3ad 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -13,13 +13,102 @@ * * ******************************************************************************/ -// create list of approved deposits, validate all deposits against this list, prevent double deposit -// need to tag deposits with OP_RETURN, ie link with originating txid/vout // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse -const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen) +struct pax_transaction { - uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + struct queueitem DL; + uint256 txid; + uint64_t komodoshis,fiatoshis; + uint16_t vout; + char symbol[4]; uint8_t rmd160[20],shortflag; +}; + +void komodo_gateway_deposits(CMutableTransaction& txNew) +{ + struct pax_transaction *ptr; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; + PENDING_KOMODO_TX = 0; + while ( (ptr= queue_dequeue(&DepositQ,0)) != 0 ) + { + txNew.vout.resize(numvouts+1); + txNew.vout[numvouts].nValue = ptr->fiatoshis; + txNew.vout[numvouts].scriptPubKey.resize(25); + script = (uint8_t *)&txNew.vout[numvouts].scriptPubKey[0]; + *script++ = 0x76; + *script++ = 0xa9; + *script++ = 20; + memcpy(script,rmd160,20), script += 20; + *script++ = 0x88; + *script++ = 0xac; + for (i=0; i<32; i++) + { + printf("%02x",((uint8_t *)&ptr->txid)[i]); + data[len++] = ((uint8_t *)&ptr->txid)[i]; + } + data[len++] = ptr->vout & 0xff; + data[len++] = (ptr->vout >> 8) & 0xff; + printf(" vout.%u DEPOSIT %.8f\n",ptr->vout,(double)KOMODO_DEPOSIT/COIN); + PENDING_KOMODO_TX += ptr->fiatoshis; + numvouts++; + queue_enqueue("PENDINGS",&PendingsQ,&ptr->DL,0); + } + if ( numvouts > 1 ) + { + opretlen = komodo_opreturnscript(opret,'I',data,len); + txNew.vout.resize(numvouts+1); + txNew.vout[numvouts].nValue = 0; + txNew.vout[numvouts].scriptPubKey.resize(opretlen); + script = (uint8_t *)&txNew.vout[numvouts].scriptPubKey[0]; + memcpy(script,opret,opretlen); + } + printf("total numvouts.%d %.8f\n",numvouts,dstr(PENDING_KOMODO_TX)); +} + +void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context +{ + struct pax_transaction *ptr; + ptr = calloc(1,sizeof(*ptr)); + ptr->komodoshis = value; + ptr->fiatoshis = fiatoshis; + memcpy(ptr->symbol,symbol,3); + memcpy(ptr->rmd160,rmd160,20) + ptr->shortflag = shortflag; + ptr->txid = txid; + ptr->vout = vout; + KOMODO_DEPOSIT += fiatoshis; + queue_enqueue("DEPOSITS",&DepositsQ,&ptr->DL,0); +} + +void komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain context +{ + int32_t iter; queue_t *Q; + for (iter=0; iter<2; iter++) + { + Q = (iter == 0) ? &DepositsQ : &PendingsQ; + portable_mutex_lock(&Q->mutex); + if ( Q->list != 0 ) + { + DL_FOREACH(Q->list,ptr) + { + if ( memcmp(&ptr->txid,&txid,sizeof(txid)) == 0 && ptr->vout == vout ) + { + if ( KOMODO_DEPOSIT >= ptr->fiatoshis ) + KOMODO_DEPOSIT -= ptr->fiatoshis; + else KOMODO_DEPOSIT = 0; + printf("DELETE %.8f DEPOSIT %s %.8f\n",dstr(ptr->value),ptr->symbol,dstr(ptr->fiatoshis)); + DL_DELETE(Q->list,ptr); + myfree(ptr,sizeof(struct queueitem)); + break; + } + } + } + portable_mutex_unlock(&Q->mutex); + } +} + +const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) +{ + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; //printf("komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); #ifdef KOMODO_ISSUER tokomodo = 1; @@ -36,31 +125,49 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis); for (i=0; i %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); - // verify price value for fiatoshis of base + printf(" DEPOSIT %.8f %c%s -> %s ",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&txid)[i]); + printf(" <- txid.v%u ",vout); for (i=0; i<33; i++) printf("%02x",pubkey33[i]); printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); typestr = "deposit"; #ifdef KOMODO_ISSUER - if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 && ((tokomodo == 0 && value >= checktoshis*.9999) || (tokomodo != 0 && value <= checktoshis/.9999)) ) + if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 && value >= (9999*checktoshis)/10000 && shortflag == ASSETCHAINS_SHORTFLAG ) { - printf("START %s MINER! %.8f\n",KOMODO_SOURCE,dstr(fiatoshis)); - KOMODO_DEPOSIT = fiatoshis; - KOMODO_SCRIPTPUBKEY[0] = 0x76; - KOMODO_SCRIPTPUBKEY[1] = 0xa9; - KOMODO_SCRIPTPUBKEY[2] = 0x14; - memcpy(&KOMODO_SCRIPTPUBKEY[3],rmd160,0x14); - KOMODO_SCRIPTPUBKEY[23] = 0x88; - KOMODO_SCRIPTPUBKEY[24] = 0xac; + komodo_gateway_deposit(value,shortflag,symbol,fiatoshis,rmd160,txid,vout); + } +#else + if ( tokomodo != 0 && value <= (10000*checktoshis)/9999 ) + { + } #endif } } + else if ( opretbuf[0] == 'I' ) + { + uint256 issuedtxid; uint16_t issuedvout; + opretbuf++, opretlen--; + for (i=len=0; i 13 ) typestr = "ratify"; @@ -92,7 +196,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr,uint32_t port) { - char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial,retval = -1; uint64_t value; + char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial,retval = -1; uint64_t value; uint256 txid; sprintf(params,"[\"%s\", 1]",txidstr); if ( (retstr= komodo_issuemethod((char *)"getrawtransaction",params,port)) != 0 ) { @@ -105,6 +209,7 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, for (vout=0; voutinitflag == 0 ) + { + portable_mutex_init(&queue->mutex); + queue->initflag = 1; + } + portable_mutex_lock(&queue->mutex); +} + +void queue_enqueue(char *name,queue_t *queue,struct queueitem *origitem,int32_t offsetflag) +{ + struct queueitem *item; + if ( queue->name[0] == 0 && name != 0 && name[0] != 0 ) + strcpy(queue->name,name);//,sizeof(queue->name)); + if ( origitem == 0 ) + { + printf("FATAL type error: queueing empty value\n");//, getchar(); + return; + } + //fprintf(stderr,"enqueue.(%s) %p offset.%d\n",queue->name,origitem,offsetflag); + lock_queue(queue); + item = (struct queueitem *)((long)origitem - offsetflag*sizeof(struct queueitem)); + DL_APPEND(queue->list,item); + portable_mutex_unlock(&queue->mutex); + //printf("queue_enqueue name.(%s) origitem.%p append.%p list.%p\n",name,origitem,item,queue->list); +} + +void *queue_dequeue(queue_t *queue,int32_t offsetflag) +{ + struct queueitem *item = 0; + lock_queue(queue); + if ( queue->list != 0 ) + { + item = queue->list; + //printf("queue_dequeue name.(%s) dequeue.%p list.%p\n",queue->name,item,queue->list); + DL_DELETE(queue->list,item); + } + portable_mutex_unlock(&queue->mutex); + if ( item != 0 && offsetflag != 0 ) + return((void *)((long)item + sizeof(struct queueitem))); + else return(item); +} + +void *queue_delete(queue_t *queue,struct queueitem *copy,int32_t copysize,int32_t freeitem) +{ + struct allocitem *ptr; + struct queueitem *item = 0; + lock_queue(queue); + if ( queue->list != 0 ) + { + DL_FOREACH(queue->list,item) + { + ptr = (void *)((long)item - sizeof(struct allocitem)); + if ( item == copy || (ptr->allocsize == copysize && memcmp((void *)((long)item + sizeof(struct queueitem)),(void *)((long)item + sizeof(struct queueitem)),copysize) == 0) ) + { + DL_DELETE(queue->list,item); + portable_mutex_unlock(&queue->mutex); + //printf("name.(%s) deleted item.%p list.%p\n",queue->name,item,queue->list); + if ( freeitem != 0 ) + myfree(item,copysize); + return(item); + } + } + } + portable_mutex_unlock(&queue->mutex); + return(0); +} + +void *queue_free(queue_t *queue) +{ + struct queueitem *item = 0; + lock_queue(queue); + if ( queue->list != 0 ) + { + DL_FOREACH(queue->list,item) + { + DL_DELETE(queue->list,item); + myfree(item,sizeof(struct queueitem)); + } + //printf("name.(%s) dequeue.%p list.%p\n",queue->name,item,queue->list); + } + portable_mutex_unlock(&queue->mutex); + return(0); +} + +void *queue_clone(queue_t *clone,queue_t *queue,int32_t size) +{ + struct queueitem *ptr,*item = 0; + lock_queue(queue); + if ( queue->list != 0 ) + { + DL_FOREACH(queue->list,item) + { + ptr = mycalloc('c',1,sizeof(*ptr)); + memcpy(ptr,item,size); + queue_enqueue(queue->name,clone,ptr,0); + } + //printf("name.(%s) dequeue.%p list.%p\n",queue->name,item,queue->list); + } + portable_mutex_unlock(&queue->mutex); + return(0); +} + +int32_t queue_size(queue_t *queue) +{ + int32_t count = 0; + struct queueitem *tmp; + lock_queue(queue); + DL_COUNT(queue->list,tmp,count); + portable_mutex_unlock(&queue->mutex); + return count; +} diff --git a/src/tinyformat.h b/src/tinyformat.h index 73d49a1fe..7d3de1de2 100644 --- a/src/tinyformat.h +++ b/src/tinyformat.h @@ -469,7 +469,7 @@ class FormatIterator void finish() { // It would be nice if we could do this from the destructor, but we - // can't if TINFORMAT_ERROR is used to throw an exception! + // can't if TINYFORMAT_ERROR is used to throw an exception! m_fmt = printFormatStringLiteral(m_out, m_fmt); if(*m_fmt != '\0') TINYFORMAT_ERROR("tinyformat: Too many conversion specifiers in format string"); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8710f96f8..ee58ed703 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2592,8 +2592,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, } else { - // Insert change txn at random position: - nChangePosRet = GetRandInt(txNew.vout.size() + 1*0); // all but last position + nChangePosRet = txNew.vout.size() - 1; // dont change first or last vector::iterator position = txNew.vout.begin()+nChangePosRet; txNew.vout.insert(position, newTxOut); } From eebc32ea25bf44be13db404f6e47dcf4994f63e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 09:53:41 -0300 Subject: [PATCH 169/205] test --- src/utlist.h | 753 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 753 insertions(+) create mode 100755 src/utlist.h diff --git a/src/utlist.h b/src/utlist.h new file mode 100755 index 000000000..93c7ceef0 --- /dev/null +++ b/src/utlist.h @@ -0,0 +1,753 @@ +/* + Copyright (c) 2007-2014, Troy D. Hanson http://troydhanson.github.com/uthash/ + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef UTLIST_H +#define UTLIST_H + +#define UTLIST_VERSION 1.9.9 + +#include + +/* + * This file contains macros to manipulate singly and doubly-linked lists. + * + * 1. LL_ macros: singly-linked lists. + * 2. DL_ macros: doubly-linked lists. + * 3. CDL_ macros: circular doubly-linked lists. + * + * To use singly-linked lists, your structure must have a "next" pointer. + * To use doubly-linked lists, your structure must "prev" and "next" pointers. + * Either way, the pointer to the head of the list must be initialized to NULL. + * + * ----------------.EXAMPLE ------------------------- + * struct item { + * int id; + * struct item *prev, *next; + * } + * + * struct item *list = NULL: + * + * int main() { + * struct item *item; + * ... allocate and populate item ... + * DL_APPEND(list, item); + * } + * -------------------------------------------------- + * + * For doubly-linked lists, the append and delete macros are O(1) + * For singly-linked lists, append and delete are O(n) but prepend is O(1) + * The sort macro is O(n log(n)) for all types of single/double/circular lists. + */ + +/* These macros use decltype or the earlier __typeof GNU extension. + As decltype is only available in newer compilers (VS2010 or gcc 4.3+ + when compiling c++ code), this code uses whatever method is needed + or, for VS2008 where neither is available, uses casting workarounds. */ +#ifdef _MSC_VER /* MS compiler */ +#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */ +#define LDECLTYPE(x) decltype(x) +#else /* VS2008 or older (or VS2010 in C mode) */ +#define NO_DECLTYPE +#define LDECLTYPE(x) char* +#endif +#elif defined(__ICCARM__) +#define NO_DECLTYPE +#define LDECLTYPE(x) char* +#else /* GNU, Sun and other compilers */ +#define LDECLTYPE(x) __typeof(x) +#endif + +/* for VS2008 we use some workarounds to get around the lack of decltype, + * namely, we always reassign our tmp variable to the list head if we need + * to dereference its prev/next pointers, and save/restore the real head.*/ +#ifdef NO_DECLTYPE +#define _SV(elt,list) _tmp = (char*)(list); {char **_alias = (char**)&(list); *_alias = (elt); } +#define _NEXT(elt,list,next) ((char*)((list)->next)) +#define _NEXTASGN(elt,list,to,next) { char **_alias = (char**)&((list)->next); *_alias=(char*)(to); } +/* #define _PREV(elt,list,prev) ((char*)((list)->prev)) */ +#define _PREVASGN(elt,list,to,prev) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); } +#define _RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; } +#define _CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); } +#else +#define _SV(elt,list) +#define _NEXT(elt,list,next) ((elt)->next) +#define _NEXTASGN(elt,list,to,next) ((elt)->next)=(to) +/* #define _PREV(elt,list,prev) ((elt)->prev) */ +#define _PREVASGN(elt,list,to,prev) ((elt)->prev)=(to) +#define _RS(list) +#define _CASTASGN(a,b) (a)=(b) +#endif + +/****************************************************************************** + * The sort macro is an adaptation of Simon Tatham's O(n log(n)) mergesort * + * Unwieldy variable names used here to avoid shadowing passed-in variables. * + *****************************************************************************/ +#define LL_SORT(list, cmp) \ +LL_SORT2(list, cmp, next) + +#define LL_SORT2(list, cmp, next) \ +do { \ +LDECLTYPE(list) _ls_p; \ +LDECLTYPE(list) _ls_q; \ +LDECLTYPE(list) _ls_e; \ +LDECLTYPE(list) _ls_tail; \ +int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ +if (list) { \ +_ls_insize = 1; \ +_ls_looping = 1; \ +while (_ls_looping) { \ +_CASTASGN(_ls_p,list); \ +list = NULL; \ +_ls_tail = NULL; \ +_ls_nmerges = 0; \ +while (_ls_p) { \ +_ls_nmerges++; \ +_ls_q = _ls_p; \ +_ls_psize = 0; \ +for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \ +_ls_psize++; \ +_SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list,next); _RS(list); \ +if (!_ls_q) break; \ +} \ +_ls_qsize = _ls_insize; \ +while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \ +if (_ls_psize == 0) { \ +_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = \ +_NEXT(_ls_q,list,next); _RS(list); _ls_qsize--; \ +} else if (_ls_qsize == 0 || !_ls_q) { \ +_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = \ +_NEXT(_ls_p,list,next); _RS(list); _ls_psize--; \ +} else if (cmp(_ls_p,_ls_q) <= 0) { \ +_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = \ +_NEXT(_ls_p,list,next); _RS(list); _ls_psize--; \ +} else { \ +_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = \ +_NEXT(_ls_q,list,next); _RS(list); _ls_qsize--; \ +} \ +if (_ls_tail) { \ +_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e,next); _RS(list); \ +} else { \ +_CASTASGN(list,_ls_e); \ +} \ +_ls_tail = _ls_e; \ +} \ +_ls_p = _ls_q; \ +} \ +if (_ls_tail) { \ +_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL,next); _RS(list); \ +} \ +if (_ls_nmerges <= 1) { \ +_ls_looping=0; \ +} \ +_ls_insize *= 2; \ +} \ +} \ +} while (0) + + +#define DL_SORT(list, cmp) \ +DL_SORT2(list, cmp, prev, next) + +#define DL_SORT2(list, cmp, prev, next) \ +do { \ +LDECLTYPE(list) _ls_p; \ +LDECLTYPE(list) _ls_q; \ +LDECLTYPE(list) _ls_e; \ +LDECLTYPE(list) _ls_tail; \ +int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ +if (list) { \ +_ls_insize = 1; \ +_ls_looping = 1; \ +while (_ls_looping) { \ +_CASTASGN(_ls_p,list); \ +list = NULL; \ +_ls_tail = NULL; \ +_ls_nmerges = 0; \ +while (_ls_p) { \ +_ls_nmerges++; \ +_ls_q = _ls_p; \ +_ls_psize = 0; \ +for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \ +_ls_psize++; \ +_SV(_ls_q,list); _ls_q = _NEXT(_ls_q,list,next); _RS(list); \ +if (!_ls_q) break; \ +} \ +_ls_qsize = _ls_insize; \ +while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \ +if (_ls_psize == 0) { \ +_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = \ +_NEXT(_ls_q,list,next); _RS(list); _ls_qsize--; \ +} else if (_ls_qsize == 0 || !_ls_q) { \ +_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = \ +_NEXT(_ls_p,list,next); _RS(list); _ls_psize--; \ +} else if (cmp(_ls_p,_ls_q) <= 0) { \ +_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = \ +_NEXT(_ls_p,list,next); _RS(list); _ls_psize--; \ +} else { \ +_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = \ +_NEXT(_ls_q,list,next); _RS(list); _ls_qsize--; \ +} \ +if (_ls_tail) { \ +_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e,next); _RS(list); \ +} else { \ +_CASTASGN(list,_ls_e); \ +} \ +_SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail,prev); _RS(list); \ +_ls_tail = _ls_e; \ +} \ +_ls_p = _ls_q; \ +} \ +_CASTASGN(list->prev, _ls_tail); \ +_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,NULL,next); _RS(list); \ +if (_ls_nmerges <= 1) { \ +_ls_looping=0; \ +} \ +_ls_insize *= 2; \ +} \ +} \ +} while (0) + +#define CDL_SORT(list, cmp) \ +CDL_SORT2(list, cmp, prev, next) + +#define CDL_SORT2(list, cmp, prev, next) \ +do { \ +LDECLTYPE(list) _ls_p; \ +LDECLTYPE(list) _ls_q; \ +LDECLTYPE(list) _ls_e; \ +LDECLTYPE(list) _ls_tail; \ +LDECLTYPE(list) _ls_oldhead; \ +LDECLTYPE(list) _tmp; \ +int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \ +if (list) { \ +_ls_insize = 1; \ +_ls_looping = 1; \ +while (_ls_looping) { \ +_CASTASGN(_ls_p,list); \ +_CASTASGN(_ls_oldhead,list); \ +list = NULL; \ +_ls_tail = NULL; \ +_ls_nmerges = 0; \ +while (_ls_p) { \ +_ls_nmerges++; \ +_ls_q = _ls_p; \ +_ls_psize = 0; \ +for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \ +_ls_psize++; \ +_SV(_ls_q,list); \ +if (_NEXT(_ls_q,list,next) == _ls_oldhead) { \ +_ls_q = NULL; \ +} else { \ +_ls_q = _NEXT(_ls_q,list,next); \ +} \ +_RS(list); \ +if (!_ls_q) break; \ +} \ +_ls_qsize = _ls_insize; \ +while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \ +if (_ls_psize == 0) { \ +_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = \ +_NEXT(_ls_q,list,next); _RS(list); _ls_qsize--; \ +if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \ +} else if (_ls_qsize == 0 || !_ls_q) { \ +_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = \ +_NEXT(_ls_p,list,next); _RS(list); _ls_psize--; \ +if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \ +} else if (cmp(_ls_p,_ls_q) <= 0) { \ +_ls_e = _ls_p; _SV(_ls_p,list); _ls_p = \ +_NEXT(_ls_p,list,next); _RS(list); _ls_psize--; \ +if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \ +} else { \ +_ls_e = _ls_q; _SV(_ls_q,list); _ls_q = \ +_NEXT(_ls_q,list,next); _RS(list); _ls_qsize--; \ +if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \ +} \ +if (_ls_tail) { \ +_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_ls_e,next); _RS(list); \ +} else { \ +_CASTASGN(list,_ls_e); \ +} \ +_SV(_ls_e,list); _PREVASGN(_ls_e,list,_ls_tail,prev); _RS(list); \ +_ls_tail = _ls_e; \ +} \ +_ls_p = _ls_q; \ +} \ +_CASTASGN(list->prev,_ls_tail); \ +_CASTASGN(_tmp,list); \ +_SV(_ls_tail,list); _NEXTASGN(_ls_tail,list,_tmp,next); _RS(list); \ +if (_ls_nmerges <= 1) { \ +_ls_looping=0; \ +} \ +_ls_insize *= 2; \ +} \ +} \ +} while (0) + +/****************************************************************************** + * singly linked list macros (non-circular) * + *****************************************************************************/ +#define LL_PREPEND(head,add) \ +LL_PREPEND2(head,add,next) + +#define LL_PREPEND2(head,add,next) \ +do { \ +(add)->next = head; \ +head = add; \ +} while (0) + +#define LL_CONCAT(head1,head2) \ +LL_CONCAT2(head1,head2,next) + +#define LL_CONCAT2(head1,head2,next) \ +do { \ +LDECLTYPE(head1) _tmp; \ +if (head1) { \ +_tmp = head1; \ +while (_tmp->next) { _tmp = _tmp->next; } \ +_tmp->next=(head2); \ +} else { \ +(head1)=(head2); \ +} \ +} while (0) + +#define LL_APPEND(head,add) \ +LL_APPEND2(head,add,next) + +#define LL_APPEND2(head,add,next) \ +do { \ +LDECLTYPE(head) _tmp; \ +(add)->next=NULL; \ +if (head) { \ +_tmp = head; \ +while (_tmp->next) { _tmp = _tmp->next; } \ +_tmp->next=(add); \ +} else { \ +(head)=(add); \ +} \ +} while (0) + +#define LL_DELETE(head,del) \ +LL_DELETE2(head,del,next) + +#define LL_DELETE2(head,del,next) \ +do { \ +LDECLTYPE(head) _tmp; \ +if ((head) == (del)) { \ +(head)=(head)->next; \ +} else { \ +_tmp = head; \ +while (_tmp->next && (_tmp->next != (del))) { \ +_tmp = _tmp->next; \ +} \ +if (_tmp->next) { \ +_tmp->next = ((del)->next); \ +} \ +} \ +} while (0) + +/* Here are VS2008 replacements for LL_APPEND and LL_DELETE */ +#define LL_APPEND_VS2008(head,add) \ +LL_APPEND2_VS2008(head,add,next) + +#define LL_APPEND2_VS2008(head,add,next) \ +do { \ +if (head) { \ +(add)->next = head; /* use add->next as a temp variable */ \ +while ((add)->next->next) { (add)->next = (add)->next->next; } \ +(add)->next->next=(add); \ +} else { \ +(head)=(add); \ +} \ +(add)->next=NULL; \ +} while (0) + +#define LL_DELETE_VS2008(head,del) \ +LL_DELETE2_VS2008(head,del,next) + +#define LL_DELETE2_VS2008(head,del,next) \ +do { \ +if ((head) == (del)) { \ +(head)=(head)->next; \ +} else { \ +char *_tmp = (char*)(head); \ +while ((head)->next && ((head)->next != (del))) { \ +head = (head)->next; \ +} \ +if ((head)->next) { \ +(head)->next = ((del)->next); \ +} \ +{ \ +char **_head_alias = (char**)&(head); \ +*_head_alias = _tmp; \ +} \ +} \ +} while (0) +#ifdef NO_DECLTYPE +#undef LL_APPEND +#define LL_APPEND LL_APPEND_VS2008 +#undef LL_DELETE +#define LL_DELETE LL_DELETE_VS2008 +#undef LL_DELETE2 +#define LL_DELETE2 LL_DELETE2_VS2008 +#undef LL_APPEND2 +#define LL_APPEND2 LL_APPEND2_VS2008 +#undef LL_CONCAT /* no LL_CONCAT_VS2008 */ +#undef DL_CONCAT /* no DL_CONCAT_VS2008 */ +#endif +/* end VS2008 replacements */ + +#define LL_COUNT(head,el,counter) \ +LL_COUNT2(head,el,counter,next) \ + +#define LL_COUNT2(head,el,counter,next) \ +{ \ +counter = 0; \ +LL_FOREACH2(head,el,next){ ++counter; } \ +} + +#define LL_FOREACH(head,el) \ +LL_FOREACH2(head,el,next) + +#define LL_FOREACH2(head,el,next) \ +for(el=head;el;el=(el)->next) + +#define LL_FOREACH_SAFE(head,el,tmp) \ +LL_FOREACH_SAFE2(head,el,tmp,next) + +#define LL_FOREACH_SAFE2(head,el,tmp,next) \ +for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp) + +#define LL_SEARCH_SCALAR(head,out,field,val) \ +LL_SEARCH_SCALAR2(head,out,field,val,next) + +#define LL_SEARCH_SCALAR2(head,out,field,val,next) \ +do { \ +LL_FOREACH2(head,out,next) { \ +if ((out)->field == (val)) break; \ +} \ +} while(0) + +#define LL_SEARCH(head,out,elt,cmp) \ +LL_SEARCH2(head,out,elt,cmp,next) + +#define LL_SEARCH2(head,out,elt,cmp,next) \ +do { \ +LL_FOREACH2(head,out,next) { \ +if ((cmp(out,elt))==0) break; \ +} \ +} while(0) + +#define LL_REPLACE_ELEM(head, el, add) \ +do { \ +LDECLTYPE(head) _tmp; \ +assert(head != NULL); \ +assert(el != NULL); \ +assert(add != NULL); \ +(add)->next = (el)->next; \ +if ((head) == (el)) { \ +(head) = (add); \ +} else { \ +_tmp = head; \ +while (_tmp->next && (_tmp->next != (el))) { \ +_tmp = _tmp->next; \ +} \ +if (_tmp->next) { \ +_tmp->next = (add); \ +} \ +} \ +} while (0) + +#define LL_PREPEND_ELEM(head, el, add) \ +do { \ +LDECLTYPE(head) _tmp; \ +assert(head != NULL); \ +assert(el != NULL); \ +assert(add != NULL); \ +(add)->next = (el); \ +if ((head) == (el)) { \ +(head) = (add); \ +} else { \ +_tmp = head; \ +while (_tmp->next && (_tmp->next != (el))) { \ +_tmp = _tmp->next; \ +} \ +if (_tmp->next) { \ +_tmp->next = (add); \ +} \ +} \ +} while (0) \ + + +/****************************************************************************** + * doubly linked list macros (non-circular) * + *****************************************************************************/ +#define DL_PREPEND(head,add) \ +DL_PREPEND2(head,add,prev,next) + +#define DL_PREPEND2(head,add,prev,next) \ +do { \ +(add)->next = head; \ +if (head) { \ +(add)->prev = (head)->prev; \ +(head)->prev = (add); \ +} else { \ +(add)->prev = (add); \ +} \ +(head) = (add); \ +} while (0) + +#define DL_APPEND(head,add) \ +DL_APPEND2(head,add,prev,next) + +#define DL_APPEND2(head,add,prev,next) \ +do { \ +if (head) { \ +(add)->prev = (head)->prev; \ +(head)->prev->next = (add); \ +(head)->prev = (add); \ +(add)->next = NULL; \ +} else { \ +(head)=(add); \ +(head)->prev = (head); \ +(head)->next = NULL; \ +} \ +} while (0) + +#define DL_CONCAT(head1,head2) \ +DL_CONCAT2(head1,head2,prev,next) + +#define DL_CONCAT2(head1,head2,prev,next) \ +do { \ +LDECLTYPE(head1) _tmp; \ +if (head2) { \ +if (head1) { \ +_tmp = (head2)->prev; \ +(head2)->prev = (head1)->prev; \ +(head1)->prev->next = (head2); \ +(head1)->prev = _tmp; \ +} else { \ +(head1)=(head2); \ +} \ +} \ +} while (0) + +#define DL_DELETE(head,del) \ +DL_DELETE2(head,del,prev,next) + +#define DL_DELETE2(head,del,prev,next) \ +do { \ +assert((del)->prev != NULL); \ +if ((del)->prev == (del)) { \ +(head)=NULL; \ +} else if ((del)==(head)) { \ +(del)->next->prev = (del)->prev; \ +(head) = (del)->next; \ +} else { \ +(del)->prev->next = (del)->next; \ +if ((del)->next) { \ +(del)->next->prev = (del)->prev; \ +} else { \ +(head)->prev = (del)->prev; \ +} \ +} \ +} while (0) + +#define DL_COUNT(head,el,counter) \ +DL_COUNT2(head,el,counter,next) \ + +#define DL_COUNT2(head,el,counter,next) \ +{ \ +counter = 0; \ +DL_FOREACH2(head,el,next){ ++counter; } \ +} + +#define DL_FOREACH(head,el) \ +DL_FOREACH2(head,el,next) + +#define DL_FOREACH2(head,el,next) \ +for(el=head;el;el=(el)->next) + +/* this version is safe for deleting the elements during iteration */ +#define DL_FOREACH_SAFE(head,el,tmp) \ +DL_FOREACH_SAFE2(head,el,tmp,next) + +#define DL_FOREACH_SAFE2(head,el,tmp,next) \ +for((el)=(head);(el) && (tmp = (el)->next, 1); (el) = tmp) + +/* these are identical to their singly-linked list counterparts */ +#define DL_SEARCH_SCALAR LL_SEARCH_SCALAR +#define DL_SEARCH LL_SEARCH +#define DL_SEARCH_SCALAR2 LL_SEARCH_SCALAR2 +#define DL_SEARCH2 LL_SEARCH2 + +#define DL_REPLACE_ELEM(head, el, add) \ +do { \ +assert(head != NULL); \ +assert(el != NULL); \ +assert(add != NULL); \ +if ((head) == (el)) { \ +(head) = (add); \ +(add)->next = (el)->next; \ +if ((el)->next == NULL) { \ +(add)->prev = (add); \ +} else { \ +(add)->prev = (el)->prev; \ +(add)->next->prev = (add); \ +} \ +} else { \ +(add)->next = (el)->next; \ +(add)->prev = (el)->prev; \ +(add)->prev->next = (add); \ +if ((el)->next == NULL) { \ +(head)->prev = (add); \ +} else { \ +(add)->next->prev = (add); \ +} \ +} \ +} while (0) + +#define DL_PREPEND_ELEM(head, el, add) \ +do { \ +assert(head != NULL); \ +assert(el != NULL); \ +assert(add != NULL); \ +(add)->next = (el); \ +(add)->prev = (el)->prev; \ +(el)->prev = (add); \ +if ((head) == (el)) { \ +(head) = (add); \ +} else { \ +(add)->prev->next = (add); \ +} \ +} while (0) \ + + +/****************************************************************************** + * circular doubly linked list macros * + *****************************************************************************/ +#define CDL_PREPEND(head,add) \ +CDL_PREPEND2(head,add,prev,next) + +#define CDL_PREPEND2(head,add,prev,next) \ +do { \ +if (head) { \ +(add)->prev = (head)->prev; \ +(add)->next = (head); \ +(head)->prev = (add); \ +(add)->prev->next = (add); \ +} else { \ +(add)->prev = (add); \ +(add)->next = (add); \ +} \ +(head)=(add); \ +} while (0) + +#define CDL_DELETE(head,del) \ +CDL_DELETE2(head,del,prev,next) + +#define CDL_DELETE2(head,del,prev,next) \ +do { \ +if ( ((head)==(del)) && ((head)->next == (head))) { \ +(head) = 0L; \ +} else { \ +(del)->next->prev = (del)->prev; \ +(del)->prev->next = (del)->next; \ +if ((del) == (head)) (head)=(del)->next; \ +} \ +} while (0) + +#define CDL_COUNT(head,el,counter) \ +CDL_COUNT2(head,el,counter,next) \ + +#define CDL_COUNT2(head, el, counter,next) \ +{ \ +counter = 0; \ +CDL_FOREACH2(head,el,next){ ++counter; } \ +} + +#define CDL_FOREACH(head,el) \ +CDL_FOREACH2(head,el,next) + +#define CDL_FOREACH2(head,el,next) \ +for(el=head;el;el=((el)->next==head ? 0L : (el)->next)) + +#define CDL_FOREACH_SAFE(head,el,tmp1,tmp2) \ +CDL_FOREACH_SAFE2(head,el,tmp1,tmp2,prev,next) + +#define CDL_FOREACH_SAFE2(head,el,tmp1,tmp2,prev,next) \ +for((el)=(head), ((tmp1)=(head)?((head)->prev):NULL); \ +(el) && ((tmp2)=(el)->next, 1); \ +((el) = (((el)==(tmp1)) ? 0L : (tmp2)))) + +#define CDL_SEARCH_SCALAR(head,out,field,val) \ +CDL_SEARCH_SCALAR2(head,out,field,val,next) + +#define CDL_SEARCH_SCALAR2(head,out,field,val,next) \ +do { \ +CDL_FOREACH2(head,out,next) { \ +if ((out)->field == (val)) break; \ +} \ +} while(0) + +#define CDL_SEARCH(head,out,elt,cmp) \ +CDL_SEARCH2(head,out,elt,cmp,next) + +#define CDL_SEARCH2(head,out,elt,cmp,next) \ +do { \ +CDL_FOREACH2(head,out,next) { \ +if ((cmp(out,elt))==0) break; \ +} \ +} while(0) + +#define CDL_REPLACE_ELEM(head, el, add) \ +do { \ +assert(head != NULL); \ +assert(el != NULL); \ +assert(add != NULL); \ +if ((el)->next == (el)) { \ +(add)->next = (add); \ +(add)->prev = (add); \ +(head) = (add); \ +} else { \ +(add)->next = (el)->next; \ +(add)->prev = (el)->prev; \ +(add)->next->prev = (add); \ +(add)->prev->next = (add); \ +if ((head) == (el)) { \ +(head) = (add); \ +} \ +} \ +} while (0) + +#define CDL_PREPEND_ELEM(head, el, add) \ +do { \ +assert(head != NULL); \ +assert(el != NULL); \ +assert(add != NULL); \ +(add)->next = (el); \ +(add)->prev = (el)->prev; \ +(el)->prev = (add); \ +(add)->prev->next = (add); \ +if ((head) == (el)) { \ +(head) = (add); \ +} \ +} while (0) \ + +#endif /* UTLIST_H */ From a18fbdc5413c1769ab02ea6860e639ca59256e83 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 09:57:40 -0300 Subject: [PATCH 170/205] test --- src/komodo_notary.h | 2 ++ src/komodo_utils.h | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index f9693f075..62b03dfdd 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -198,6 +198,8 @@ void komodo_init() if ( didinit == 0 ) { didinit = 1; + iguana_initQ(&DepositsQ,"Deposits"); + iguana_initQ(&PendingsQ,"Pendings"); pthread_mutex_init(&komodo_mutex,NULL); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); n = (int32_t)(sizeof(Notaries)/sizeof(*Notaries)); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ab80a9bc7..69b5ca780 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -16,6 +16,13 @@ #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) +typedef struct queue +{ + struct queueitem *list; + portable_mutex_t mutex; + char name[64],initflag; +} queue_t; + union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; typedef union _bits256 bits256; @@ -1216,3 +1223,13 @@ int32_t queue_size(queue_t *queue) portable_mutex_unlock(&queue->mutex); return count; } + +void iguana_initQ(queue_t *Q,char *name) +{ + char *tst,*str = "need to init each Q when single threaded"; + memset(Q,0,sizeof(*Q)); + strcpy(Q->name,name); + queue_enqueue(name,Q,queueitem(str),1); + if ( (tst= queue_dequeue(Q,1)) != 0 ) + free_queueitem(tst); +} From 0a912c896cb330e805c1d7d95db187681da97084 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:01:53 -0300 Subject: [PATCH 171/205] test --- src/komodo_utils.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 69b5ca780..2905836ca 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -16,10 +16,12 @@ #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) +struct queueitem { struct queueitem *next,*prev; uint32_t allocsize,type; }; + typedef struct queue { struct queueitem *list; - portable_mutex_t mutex; + pthread_mutex_t mutex; char name[64],initflag; } queue_t; From b67b154f1e0987e9c5dd9138125345e6f0daff9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:04:03 -0300 Subject: [PATCH 172/205] test --- src/komodo_utils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2905836ca..686da09f5 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -15,6 +15,10 @@ #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) +#define portable_mutex_t pthread_mutex_t +#define portable_mutex_init(ptr) pthread_mutex_init(ptr,NULL) +#define portable_mutex_lock pthread_mutex_lock +#define portable_mutex_unlock pthread_mutex_unlock struct queueitem { struct queueitem *next,*prev; uint32_t allocsize,type; }; From 2552dbb4ed6ec940f7a32daa8313a31c86ca02a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:05:13 -0300 Subject: [PATCH 173/205] test --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 686da09f5..b0836d31d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -20,6 +20,7 @@ #define portable_mutex_lock pthread_mutex_lock #define portable_mutex_unlock pthread_mutex_unlock +struct allocitem { uint32_t allocsize,type; }; struct queueitem { struct queueitem *next,*prev; uint32_t allocsize,type; }; typedef struct queue From 405e2bdd15e766d9365ac9ce2d69f998506accff Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:10:17 -0300 Subject: [PATCH 174/205] test --- src/komodo_utils.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index b0836d31d..51e0d0e66 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1117,6 +1117,17 @@ double OS_milliseconds() return(millis); } +void myfree(void *_ptr,long allocsize) +{ + struct allocitem *item = (void *)((long)_ptr - sizeof(struct allocitem)); + if ( allocsize == 0 ) + { + printf("myfree zero allocsize %p?\n",_ptr); + return; + } + free(item); +} + void lock_queue(queue_t *queue) { if ( queue->initflag == 0 ) @@ -1161,7 +1172,7 @@ void *queue_dequeue(queue_t *queue,int32_t offsetflag) else return(item); } -void *queue_delete(queue_t *queue,struct queueitem *copy,int32_t copysize,int32_t freeitem) +void *queue_delete(queue_t *queue,struct queueitem *copy,int32_t copysize) { struct allocitem *ptr; struct queueitem *item = 0; @@ -1170,14 +1181,12 @@ void *queue_delete(queue_t *queue,struct queueitem *copy,int32_t copysize,int32_ { DL_FOREACH(queue->list,item) { - ptr = (void *)((long)item - sizeof(struct allocitem)); + ptr = (struct allocitem *)((long)item - sizeof(struct allocitem)); if ( item == copy || (ptr->allocsize == copysize && memcmp((void *)((long)item + sizeof(struct queueitem)),(void *)((long)item + sizeof(struct queueitem)),copysize) == 0) ) { DL_DELETE(queue->list,item); portable_mutex_unlock(&queue->mutex); //printf("name.(%s) deleted item.%p list.%p\n",queue->name,item,queue->list); - if ( freeitem != 0 ) - myfree(item,copysize); return(item); } } From f65224b79b0120cadaab8a76720b3f75ac51550e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:14:29 -0300 Subject: [PATCH 175/205] test --- src/komodo_utils.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 51e0d0e66..84b278ff7 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1119,7 +1119,7 @@ double OS_milliseconds() void myfree(void *_ptr,long allocsize) { - struct allocitem *item = (void *)((long)_ptr - sizeof(struct allocitem)); + struct allocitem *item = (struct allocitem *)((long)_ptr - sizeof(struct allocitem)); if ( allocsize == 0 ) { printf("myfree zero allocsize %p?\n",_ptr); @@ -1128,6 +1128,25 @@ void myfree(void *_ptr,long allocsize) free(item); } +void *mycalloc(uint8_t type,int32_t n,long itemsize) +{ + struct allocitem *item; int64_t allocsize = ((uint64_t)n * itemsize); + if ( type == 0 && n == 0 && itemsize == 0 ) + { + myfree(mycalloc('t',1024,1024 * 32),1024*1024*32); + return(0); + } + while ( (item= (struct allocitem *)calloc(1,sizeof(struct allocitem) + allocsize + 16)) == 0 ) + { + char str[65]; + printf("mycalloc.%c: need to wait for memory.(%d,%ld) %s to be available\n",type,n,itemsize,mbstr(str,allocsize)); + sleep(10); + } + item->allocsize = (uint32_t)allocsize; + item->type = type; + return((void *)((long)item + sizeof(*item))); +} + void lock_queue(queue_t *queue) { if ( queue->initflag == 0 ) From f4d61fa7c40b219b6c38b99d599cba51ff68abce Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:17:29 -0300 Subject: [PATCH 176/205] test --- src/komodo_utils.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 84b278ff7..460f5e8bb 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1139,7 +1139,7 @@ void *mycalloc(uint8_t type,int32_t n,long itemsize) while ( (item= (struct allocitem *)calloc(1,sizeof(struct allocitem) + allocsize + 16)) == 0 ) { char str[65]; - printf("mycalloc.%c: need to wait for memory.(%d,%ld) %s to be available\n",type,n,itemsize,mbstr(str,allocsize)); + printf("mycalloc.%c: need to wait for memory.(%d,%ld) to be available\n",type,n,itemsize); sleep(10); } item->allocsize = (uint32_t)allocsize; @@ -1239,7 +1239,7 @@ void *queue_clone(queue_t *clone,queue_t *queue,int32_t size) { DL_FOREACH(queue->list,item) { - ptr = mycalloc('c',1,sizeof(*ptr)); + ptr = (struct queueitem *)mycalloc('c',1,sizeof(*ptr)); memcpy(ptr,item,size); queue_enqueue(queue->name,clone,ptr,0); } @@ -1259,9 +1259,29 @@ int32_t queue_size(queue_t *queue) return count; } +void *queueitem(char *str) +{ + struct queueitem *item; int32_t n,allocsize; char *data; uint8_t type = 'y'; + n = (uint32_t)strlen(str) + 1; + allocsize = (uint32_t)(sizeof(struct queueitem) + n); + while ( (item= (struct queueitem *)calloc(1,allocsize)) == 0 ) + { + char str[65]; + printf("queueitem: need to wait for memory.(%d,%ld) to be available\n",n,(long)sizeof(*item)); + sleep(10); + } + item->allocsize = (uint32_t)allocsize; + item->type = type; + data = (char *)(long)((long)item + sizeof(*item)); + memcpy(data,str,n); + //printf("(%c) queueitem.%p itemdata.%p n.%d allocsize.%d\n",type,item,data,n,allocsize); + //portable_mutex_unlock(&MEMmutex); + return(data); +} + void iguana_initQ(queue_t *Q,char *name) { - char *tst,*str = "need to init each Q when single threaded"; + char *tst,*str = (char *)"need to init each Q when single threaded"; memset(Q,0,sizeof(*Q)); strcpy(Q->name,name); queue_enqueue(name,Q,queueitem(str),1); From bf301bb67f9ad0c9b51e8e592d9fc64c234ef3b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:20:00 -0300 Subject: [PATCH 177/205] test --- src/komodo_notary.h | 4 ++-- src/komodo_utils.h | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 62b03dfdd..45d2249c8 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -198,8 +198,8 @@ void komodo_init() if ( didinit == 0 ) { didinit = 1; - iguana_initQ(&DepositsQ,"Deposits"); - iguana_initQ(&PendingsQ,"Pendings"); + iguana_initQ(&DepositsQ,(char *)"Deposits"); + iguana_initQ(&PendingsQ,(char *)"Pendings"); pthread_mutex_init(&komodo_mutex,NULL); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); n = (int32_t)(sizeof(Notaries)/sizeof(*Notaries)); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 460f5e8bb..08bd5ca38 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1128,6 +1128,13 @@ void myfree(void *_ptr,long allocsize) free(item); } +void free_queueitem(void *itemdata) +{ + struct queueitem *item = (void *)((long)itemdata - sizeof(struct queueitem)); + //printf("freeq item.%p itemdata.%p size.%d\n",item,itemdata,item->allocsize); + _myfree(item->type,item->allocsize,item,item->allocsize); +} + void *mycalloc(uint8_t type,int32_t n,long itemsize) { struct allocitem *item; int64_t allocsize = ((uint64_t)n * itemsize); @@ -1284,7 +1291,7 @@ void iguana_initQ(queue_t *Q,char *name) char *tst,*str = (char *)"need to init each Q when single threaded"; memset(Q,0,sizeof(*Q)); strcpy(Q->name,name); - queue_enqueue(name,Q,queueitem(str),1); - if ( (tst= queue_dequeue(Q,1)) != 0 ) + queue_enqueue(name,Q,(struct queueitem *)queueitem(str),1); + if ( (tst= (char *)queue_dequeue(Q,1)) != 0 ) free_queueitem(tst); } From b9a9c9fae5be6d5690e1d76319c5b988e6e460e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:24:27 -0300 Subject: [PATCH 178/205] test --- src/komodo_gateway.h | 12 ++++++------ src/komodo_utils.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c6386d3ad..f07238d72 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -28,7 +28,7 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) { struct pax_transaction *ptr; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - while ( (ptr= queue_dequeue(&DepositQ,0)) != 0 ) + while ( (ptr= queue_dequeue(&DepositsQ,0)) != 0 ) { txNew.vout.resize(numvouts+1); txNew.vout[numvouts].nValue = ptr->fiatoshis; @@ -37,7 +37,7 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) *script++ = 0x76; *script++ = 0xa9; *script++ = 20; - memcpy(script,rmd160,20), script += 20; + memcpy(script,ptr->rmd160,20), script += 20; *script++ = 0x88; *script++ = 0xac; for (i=0; i<32; i++) @@ -50,7 +50,7 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) printf(" vout.%u DEPOSIT %.8f\n",ptr->vout,(double)KOMODO_DEPOSIT/COIN); PENDING_KOMODO_TX += ptr->fiatoshis; numvouts++; - queue_enqueue("PENDINGS",&PendingsQ,&ptr->DL,0); + queue_enqueue((char *)"PENDINGS",&PendingsQ,&ptr->DL,0); } if ( numvouts > 1 ) { @@ -67,7 +67,7 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context { struct pax_transaction *ptr; - ptr = calloc(1,sizeof(*ptr)); + ptr = (struct pax_transaction *)calloc(1,sizeof(*ptr)); ptr->komodoshis = value; ptr->fiatoshis = fiatoshis; memcpy(ptr->symbol,symbol,3); @@ -76,12 +76,12 @@ void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64 ptr->txid = txid; ptr->vout = vout; KOMODO_DEPOSIT += fiatoshis; - queue_enqueue("DEPOSITS",&DepositsQ,&ptr->DL,0); + queue_enqueue((char *)"DEPOSITS",&DepositsQ,&ptr->DL,0); } void komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain context { - int32_t iter; queue_t *Q; + int32_t iter; queue_t *Q; struct pax_transaction *ptr; for (iter=0; iter<2; iter++) { Q = (iter == 0) ? &DepositsQ : &PendingsQ; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 08bd5ca38..329fd8de4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1130,9 +1130,9 @@ void myfree(void *_ptr,long allocsize) void free_queueitem(void *itemdata) { - struct queueitem *item = (void *)((long)itemdata - sizeof(struct queueitem)); + struct queueitem *item = (struct queueitem *)((long)itemdata - sizeof(struct queueitem)); //printf("freeq item.%p itemdata.%p size.%d\n",item,itemdata,item->allocsize); - _myfree(item->type,item->allocsize,item,item->allocsize); + myfree(item,item->allocsize); } void *mycalloc(uint8_t type,int32_t n,long itemsize) From 19b3d41f26f145921f113b6346b0580123f16b92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:26:15 -0300 Subject: [PATCH 179/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f07238d72..cebe644dc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -28,7 +28,7 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) { struct pax_transaction *ptr; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - while ( (ptr= queue_dequeue(&DepositsQ,0)) != 0 ) + while ( (ptr= (struct pax_transaction *)queue_dequeue(&DepositsQ,0)) != 0 ) { txNew.vout.resize(numvouts+1); txNew.vout[numvouts].nValue = ptr->fiatoshis; @@ -71,7 +71,7 @@ void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64 ptr->komodoshis = value; ptr->fiatoshis = fiatoshis; memcpy(ptr->symbol,symbol,3); - memcpy(ptr->rmd160,rmd160,20) + memcpy(ptr->rmd160,rmd160,20); ptr->shortflag = shortflag; ptr->txid = txid; ptr->vout = vout; From a730c1c3203177ad4e6d36f475f55802b0711d61 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:29:39 -0300 Subject: [PATCH 180/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cebe644dc..644eaa385 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -88,7 +88,7 @@ void komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain cont portable_mutex_lock(&Q->mutex); if ( Q->list != 0 ) { - DL_FOREACH(Q->list,ptr) + DL_FOREACH(Q->list,&ptr->DL) { if ( memcmp(&ptr->txid,&txid,sizeof(txid)) == 0 && ptr->vout == vout ) { @@ -96,7 +96,7 @@ void komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain cont KOMODO_DEPOSIT -= ptr->fiatoshis; else KOMODO_DEPOSIT = 0; printf("DELETE %.8f DEPOSIT %s %.8f\n",dstr(ptr->value),ptr->symbol,dstr(ptr->fiatoshis)); - DL_DELETE(Q->list,ptr); + DL_DELETE(Q->list,&ptr->DL); myfree(ptr,sizeof(struct queueitem)); break; } From eae0d2e5dff8f0873a5b7567247ed619ac0a054a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:34:02 -0300 Subject: [PATCH 181/205] test --- src/komodo_gateway.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 644eaa385..e80109166 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -79,9 +79,9 @@ void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64 queue_enqueue((char *)"DEPOSITS",&DepositsQ,&ptr->DL,0); } -void komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain context +int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain context { - int32_t iter; queue_t *Q; struct pax_transaction *ptr; + int32_t iter,n=0; queue_t *Q; struct pax_transaction *ptr; for (iter=0; iter<2; iter++) { Q = (iter == 0) ? &DepositsQ : &PendingsQ; @@ -95,8 +95,9 @@ void komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain cont if ( KOMODO_DEPOSIT >= ptr->fiatoshis ) KOMODO_DEPOSIT -= ptr->fiatoshis; else KOMODO_DEPOSIT = 0; - printf("DELETE %.8f DEPOSIT %s %.8f\n",dstr(ptr->value),ptr->symbol,dstr(ptr->fiatoshis)); + printf("DELETE %.8f DEPOSIT %s %.8f\n",dstr(ptr->komodoshis),ptr->symbol,dstr(ptr->fiatoshis)); DL_DELETE(Q->list,&ptr->DL); + n++; myfree(ptr,sizeof(struct queueitem)); break; } @@ -104,6 +105,7 @@ void komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain cont } portable_mutex_unlock(&Q->mutex); } + return(n); } const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) @@ -160,17 +162,18 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 issuedvout = opretbuf[len++]; issuedvout = (vout << 8) | opretbuf[len++]; printf(" issuedtxid v%d i.%d opretlen.%d\n",issuedvout,i,opretlen); - if ( komodo_gateway_depositremove(issuedtxid,issuedvout) < 0 ) + if ( komodo_gateway_depositremove(issuedtxid,issuedvout) == 0 ) printf("error removing deposit\n"); } } return(typestr); } -void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int32_t txi,uint256 txid,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) +void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int32_t txi,bits256 txid,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len) { - int32_t i,opretlen,offset = 0; uint256 zero; const char *typestr; + int32_t i,opretlen,offset = 0; uint256 zero,utxid; const char *typestr; typestr = "unknown"; + memcpy(&utxid,&txid,sizeof(utxid)); if ( 0 )//txi != 0 || vout != 0 ) { for (i=0; i 13 ) typestr = "ratify"; @@ -196,7 +199,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr,uint32_t port) { - char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial,retval = -1; uint64_t value; uint256 txid; + char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial,retval = -1; uint64_t value; bits256 txid; sprintf(params,"[\"%s\", 1]",txidstr); if ( (retstr= komodo_issuemethod((char *)"getrawtransaction",params,port)) != 0 ) { From 364094141d7085a2373659ee4e392306a096181b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:35:20 -0300 Subject: [PATCH 182/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e80109166..d79affae0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -88,7 +88,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c portable_mutex_lock(&Q->mutex); if ( Q->list != 0 ) { - DL_FOREACH(Q->list,&ptr->DL) + DL_FOREACH(Q->list,&ptr->DL.DL) { if ( memcmp(&ptr->txid,&txid,sizeof(txid)) == 0 && ptr->vout == vout ) { From e8548bcb43126b18da360193844354a246b18a42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:38:48 -0300 Subject: [PATCH 183/205] test --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d79affae0..6de58789a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -81,14 +81,15 @@ void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64 int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain context { - int32_t iter,n=0; queue_t *Q; struct pax_transaction *ptr; + int32_t iter,n=0; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; for (iter=0; iter<2; iter++) { Q = (iter == 0) ? &DepositsQ : &PendingsQ; portable_mutex_lock(&Q->mutex); if ( Q->list != 0 ) { - DL_FOREACH(Q->list,&ptr->DL.DL) + item = &ptr->DL; + DL_FOREACH(Q->list,item) { if ( memcmp(&ptr->txid,&txid,sizeof(txid)) == 0 && ptr->vout == vout ) { From 4b13149d79dd435d686f4b5cd198cb45c4ae7e30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:42:43 -0300 Subject: [PATCH 184/205] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 2 +- src/komodo_utils.h | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 3e0e43a44..d33329d6d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -259,7 +259,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value) { - static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; + static uint256 zero; int32_t opretlen,nid,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6de58789a..c2c1cfff2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -139,7 +139,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 #ifdef KOMODO_ISSUER if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 && value >= (9999*checktoshis)/10000 && shortflag == ASSETCHAINS_SHORTFLAG ) { - komodo_gateway_deposit(value,shortflag,symbol,fiatoshis,rmd160,txid,vout); + komodo_gateway_deposit(value,shortflag,base,fiatoshis,rmd160,txid,vout); } #else if ( tokomodo != 0 && value <= (10000*checktoshis)/9999 ) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 329fd8de4..557a0d9ac 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1145,7 +1145,6 @@ void *mycalloc(uint8_t type,int32_t n,long itemsize) } while ( (item= (struct allocitem *)calloc(1,sizeof(struct allocitem) + allocsize + 16)) == 0 ) { - char str[65]; printf("mycalloc.%c: need to wait for memory.(%d,%ld) to be available\n",type,n,itemsize); sleep(10); } @@ -1273,7 +1272,6 @@ void *queueitem(char *str) allocsize = (uint32_t)(sizeof(struct queueitem) + n); while ( (item= (struct queueitem *)calloc(1,allocsize)) == 0 ) { - char str[65]; printf("queueitem: need to wait for memory.(%d,%ld) to be available\n",n,(long)sizeof(*item)); sleep(10); } From 552eb795a3e7578cde3819d3924a62e58a88e287 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 10:44:59 -0300 Subject: [PATCH 185/205] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c2c1cfff2..4dd651aaf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -91,6 +91,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c item = &ptr->DL; DL_FOREACH(Q->list,item) { + ptr = (struct pax_transaction *)item; if ( memcmp(&ptr->txid,&txid,sizeof(txid)) == 0 && ptr->vout == vout ) { if ( KOMODO_DEPOSIT >= ptr->fiatoshis ) From 5fa92ab265146c11b9ef41ab192d57958546b260 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 11:06:44 -0300 Subject: [PATCH 186/205] test --- src/komodo_utils.h | 93 ++++++++-------------------------------------- 1 file changed, 15 insertions(+), 78 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 557a0d9ac..a26325c3a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1117,42 +1117,6 @@ double OS_milliseconds() return(millis); } -void myfree(void *_ptr,long allocsize) -{ - struct allocitem *item = (struct allocitem *)((long)_ptr - sizeof(struct allocitem)); - if ( allocsize == 0 ) - { - printf("myfree zero allocsize %p?\n",_ptr); - return; - } - free(item); -} - -void free_queueitem(void *itemdata) -{ - struct queueitem *item = (struct queueitem *)((long)itemdata - sizeof(struct queueitem)); - //printf("freeq item.%p itemdata.%p size.%d\n",item,itemdata,item->allocsize); - myfree(item,item->allocsize); -} - -void *mycalloc(uint8_t type,int32_t n,long itemsize) -{ - struct allocitem *item; int64_t allocsize = ((uint64_t)n * itemsize); - if ( type == 0 && n == 0 && itemsize == 0 ) - { - myfree(mycalloc('t',1024,1024 * 32),1024*1024*32); - return(0); - } - while ( (item= (struct allocitem *)calloc(1,sizeof(struct allocitem) + allocsize + 16)) == 0 ) - { - printf("mycalloc.%c: need to wait for memory.(%d,%ld) to be available\n",type,n,itemsize); - sleep(10); - } - item->allocsize = (uint32_t)allocsize; - item->type = type; - return((void *)((long)item + sizeof(*item))); -} - void lock_queue(queue_t *queue) { if ( queue->initflag == 0 ) @@ -1163,55 +1127,46 @@ void lock_queue(queue_t *queue) portable_mutex_lock(&queue->mutex); } -void queue_enqueue(char *name,queue_t *queue,struct queueitem *origitem,int32_t offsetflag) +void queue_enqueue(char *name,queue_t *queue,struct queueitem *item) { - struct queueitem *item; if ( queue->name[0] == 0 && name != 0 && name[0] != 0 ) - strcpy(queue->name,name);//,sizeof(queue->name)); - if ( origitem == 0 ) + strcpy(queue->name,name); + if ( item == 0 ) { - printf("FATAL type error: queueing empty value\n");//, getchar(); + printf("FATAL type error: queueing empty value\n"); return; } - //fprintf(stderr,"enqueue.(%s) %p offset.%d\n",queue->name,origitem,offsetflag); lock_queue(queue); - item = (struct queueitem *)((long)origitem - offsetflag*sizeof(struct queueitem)); DL_APPEND(queue->list,item); portable_mutex_unlock(&queue->mutex); - //printf("queue_enqueue name.(%s) origitem.%p append.%p list.%p\n",name,origitem,item,queue->list); } -void *queue_dequeue(queue_t *queue,int32_t offsetflag) +struct queueitem *queue_dequeue(queue_t *queue) { struct queueitem *item = 0; lock_queue(queue); if ( queue->list != 0 ) { item = queue->list; - //printf("queue_dequeue name.(%s) dequeue.%p list.%p\n",queue->name,item,queue->list); DL_DELETE(queue->list,item); } portable_mutex_unlock(&queue->mutex); - if ( item != 0 && offsetflag != 0 ) - return((void *)((long)item + sizeof(struct queueitem))); - else return(item); + return(item); } void *queue_delete(queue_t *queue,struct queueitem *copy,int32_t copysize) { - struct allocitem *ptr; struct queueitem *item = 0; lock_queue(queue); if ( queue->list != 0 ) { DL_FOREACH(queue->list,item) { - ptr = (struct allocitem *)((long)item - sizeof(struct allocitem)); - if ( item == copy || (ptr->allocsize == copysize && memcmp((void *)((long)item + sizeof(struct queueitem)),(void *)((long)item + sizeof(struct queueitem)),copysize) == 0) ) + if ( item == copy || (item->allocsize == copysize && memcmp((void *)((long)item + sizeof(struct queueitem)),(void *)((long)copy + sizeof(struct queueitem)),copysize) == 0) ) { DL_DELETE(queue->list,item); portable_mutex_unlock(&queue->mutex); - //printf("name.(%s) deleted item.%p list.%p\n",queue->name,item,queue->list); + printf("name.(%s) deleted item.%p list.%p\n",queue->name,item,queue->list); return(item); } } @@ -1229,7 +1184,7 @@ void *queue_free(queue_t *queue) DL_FOREACH(queue->list,item) { DL_DELETE(queue->list,item); - myfree(item,sizeof(struct queueitem)); + free(item); } //printf("name.(%s) dequeue.%p list.%p\n",queue->name,item,queue->list); } @@ -1245,7 +1200,7 @@ void *queue_clone(queue_t *clone,queue_t *queue,int32_t size) { DL_FOREACH(queue->list,item) { - ptr = (struct queueitem *)mycalloc('c',1,sizeof(*ptr)); + ptr = (struct queueitem *)calloc(1,sizeof(*ptr)); memcpy(ptr,item,size); queue_enqueue(queue->name,clone,ptr,0); } @@ -1265,31 +1220,13 @@ int32_t queue_size(queue_t *queue) return count; } -void *queueitem(char *str) -{ - struct queueitem *item; int32_t n,allocsize; char *data; uint8_t type = 'y'; - n = (uint32_t)strlen(str) + 1; - allocsize = (uint32_t)(sizeof(struct queueitem) + n); - while ( (item= (struct queueitem *)calloc(1,allocsize)) == 0 ) - { - printf("queueitem: need to wait for memory.(%d,%ld) to be available\n",n,(long)sizeof(*item)); - sleep(10); - } - item->allocsize = (uint32_t)allocsize; - item->type = type; - data = (char *)(long)((long)item + sizeof(*item)); - memcpy(data,str,n); - //printf("(%c) queueitem.%p itemdata.%p n.%d allocsize.%d\n",type,item,data,n,allocsize); - //portable_mutex_unlock(&MEMmutex); - return(data); -} - void iguana_initQ(queue_t *Q,char *name) { - char *tst,*str = (char *)"need to init each Q when single threaded"; + struct queueitem *item,I; memset(Q,0,sizeof(*Q)); + memset(&I,0,sizeof(I)); strcpy(Q->name,name); - queue_enqueue(name,Q,(struct queueitem *)queueitem(str),1); - if ( (tst= (char *)queue_dequeue(Q,1)) != 0 ) - free_queueitem(tst); + queue_enqueue(name,Q,&I); + if ( (item= queue_dequeue(Q)) != 0 ) + free(item); } From 4c4100cc53e6db0aff1923f5a6d057ad488aeba1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 11:08:11 -0300 Subject: [PATCH 187/205] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4dd651aaf..fada13de3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -28,7 +28,7 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) { struct pax_transaction *ptr; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - while ( (ptr= (struct pax_transaction *)queue_dequeue(&DepositsQ,0)) != 0 ) + while ( (ptr= (struct pax_transaction *)queue_dequeue(&DepositsQ)) != 0 ) { txNew.vout.resize(numvouts+1); txNew.vout[numvouts].nValue = ptr->fiatoshis; @@ -100,7 +100,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c printf("DELETE %.8f DEPOSIT %s %.8f\n",dstr(ptr->komodoshis),ptr->symbol,dstr(ptr->fiatoshis)); DL_DELETE(Q->list,&ptr->DL); n++; - myfree(ptr,sizeof(struct queueitem)); + free(ptr); break; } } From a856c56a50fa977177cee380efc9f52269cd7064 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 11:10:00 -0300 Subject: [PATCH 188/205] test --- src/komodo_gateway.h | 4 ++-- src/komodo_utils.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index fada13de3..ed6412ed1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -50,7 +50,7 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) printf(" vout.%u DEPOSIT %.8f\n",ptr->vout,(double)KOMODO_DEPOSIT/COIN); PENDING_KOMODO_TX += ptr->fiatoshis; numvouts++; - queue_enqueue((char *)"PENDINGS",&PendingsQ,&ptr->DL,0); + queue_enqueue((char *)"PENDINGS",&PendingsQ,&ptr->DL); } if ( numvouts > 1 ) { @@ -76,7 +76,7 @@ void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64 ptr->txid = txid; ptr->vout = vout; KOMODO_DEPOSIT += fiatoshis; - queue_enqueue((char *)"DEPOSITS",&DepositsQ,&ptr->DL,0); + queue_enqueue((char *)"DEPOSITS",&DepositsQ,&ptr->DL); } int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain context diff --git a/src/komodo_utils.h b/src/komodo_utils.h index a26325c3a..81bffce6a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1202,7 +1202,7 @@ void *queue_clone(queue_t *clone,queue_t *queue,int32_t size) { ptr = (struct queueitem *)calloc(1,sizeof(*ptr)); memcpy(ptr,item,size); - queue_enqueue(queue->name,clone,ptr,0); + queue_enqueue(queue->name,clone,ptr); } //printf("name.(%s) dequeue.%p list.%p\n",queue->name,item,queue->list); } From 2531486873dcd015362c756a8c16d6e2d70155b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 11:12:50 -0300 Subject: [PATCH 189/205] test --- src/komodo_utils.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 81bffce6a..47d7f41ff 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1222,11 +1222,11 @@ int32_t queue_size(queue_t *queue) void iguana_initQ(queue_t *Q,char *name) { - struct queueitem *item,I; + struct queueitem *item,*I; memset(Q,0,sizeof(*Q)); - memset(&I,0,sizeof(I)); + I = calloc(1,sizeof(*I)); strcpy(Q->name,name); - queue_enqueue(name,Q,&I); + queue_enqueue(name,Q,I); if ( (item= queue_dequeue(Q)) != 0 ) free(item); } From 96d1da773cbe194be375794f8fbd5aa486ed33ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 11:13:42 -0300 Subject: [PATCH 190/205] 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 47d7f41ff..d1b27a160 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1224,7 +1224,7 @@ void iguana_initQ(queue_t *Q,char *name) { struct queueitem *item,*I; memset(Q,0,sizeof(*Q)); - I = calloc(1,sizeof(*I)); + I = (struct queueitem *)calloc(1,sizeof(*I)); strcpy(Q->name,name); queue_enqueue(name,Q,I); if ( (item= queue_dequeue(Q)) != 0 ) From 342e220d75d6e0bb0d291bb779767229d16acb65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 12:14:02 -0300 Subject: [PATCH 191/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ed6412ed1..c3c143dbe 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -291,7 +291,7 @@ void komodo_gateway_iteration(char *symbol) { for (i=0; i<1000 && KMDHEIGHT Date: Thu, 27 Oct 2016 12:35:33 -0300 Subject: [PATCH 192/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index d33329d6d..cdead9c83 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -28,7 +28,7 @@ void komodo_init(); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *method,char *params,uint16_t port); -int32_t ASSETCHAINS_SHORTFLAG,NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 40000; +int32_t ASSETCHAINS_SHORTFLAG,NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 43000; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; From e790fe9c032b667e1d02fbd4a9d9312613234b7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 12:38:30 -0300 Subject: [PATCH 193/205] test --- src/komodo_gateway.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c3c143dbe..bbc6aacd4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -107,6 +107,8 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c } portable_mutex_unlock(&Q->mutex); } + if ( queuesize(&DepositsQ) == 0 && queuesize(&PendingsQ) == 0 ) + KOMODO_DEPOSIT = 0; return(n); } From cd21f5a6819d46779856283cdaef6655843d1ff4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 12:39:47 -0300 Subject: [PATCH 194/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bbc6aacd4..2b69c8826 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -107,7 +107,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c } portable_mutex_unlock(&Q->mutex); } - if ( queuesize(&DepositsQ) == 0 && queuesize(&PendingsQ) == 0 ) + if ( queue_size(&DepositsQ) == 0 && queue_size(&PendingsQ) == 0 ) KOMODO_DEPOSIT = 0; return(n); } From aecaf4bdc41548f29a22d6406e9dd57c530cc606 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 13:00:32 -0300 Subject: [PATCH 195/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2b69c8826..83204716a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -213,10 +213,10 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, { retval = 0; isspecial = 0; + txid = jbits256(result,(char *)"txid"); for (vout=0; vout Date: Thu, 27 Oct 2016 13:15:40 -0300 Subject: [PATCH 196/205] test --- src/komodo_gateway.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 83204716a..2d9d9de33 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -223,13 +223,12 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, if ( (hexstr= jstr(sobj,(char *)"hex")) != 0 ) { len = (int32_t)strlen(hexstr) >> 1; - if ( 0 && len != 74 ) - printf("ht.%d txi.%d vout.%d/%d %s script (%d %d)\n",height,txi,vout,n,hexstr,memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66),memcmp(&hexstr[6],CRYPTO777_RMD160STR,40)); if ( vout == 0 && ((memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35) || (memcmp(&hexstr[6],CRYPTO777_RMD160STR,40) == 0 && len == 25)) ) isspecial = 1; else if ( len <= sizeof(script) ) { decode_hex(script,len,hexstr); + printf("call voutupdate vout.%d\n",vout); komodo_gateway_voutupdate(symbol,isspecial,height,txi,txid,vout,n,value,script,len); } } From f671a131a62e2c129b283a51467c6ea53a8eef03 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 13:19:35 -0300 Subject: [PATCH 197/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index cdead9c83..c3b59aae9 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -191,7 +191,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; //printf("ht.%d R opret[%d]\n",height,olen); - komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,numvouts); + komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); } else if ( notarypubs != 0 && numnotaries > 0 ) { From ec35af90c02327a5c6b40a4555bd4781dfb5f012 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 13:24:47 -0300 Subject: [PATCH 198/205] test --- src/komodo_gateway.h | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2d9d9de33..30164247f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -115,7 +115,6 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; - //printf("komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); #ifdef KOMODO_ISSUER tokomodo = 1; #endif @@ -152,22 +151,29 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 #endif } } - else if ( opretbuf[0] == 'I' ) + else { - uint256 issuedtxid; uint16_t issuedvout; - opretbuf++, opretlen--; - for (i=len=0; i Date: Thu, 27 Oct 2016 13:25:57 -0300 Subject: [PATCH 199/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 30164247f..bb8c18e34 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -153,7 +153,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else { - for (i=0; i Date: Thu, 27 Oct 2016 13:26:52 -0300 Subject: [PATCH 200/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bb8c18e34..df30c1dae 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -154,7 +154,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 else { for (i=0; i Date: Thu, 27 Oct 2016 13:37:00 -0300 Subject: [PATCH 201/205] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index df30c1dae..e16bffab4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -169,7 +169,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf("%02x",((uint8_t *)&issuedtxid)[j]); } issuedvout = opretbuf[len++]; - issuedvout = (vout << 8) | opretbuf[len++]; + issuedvout = (opretbuf[len++] << 8) | vout; printf(" issuedtxid v%d i.%d opretlen.%d\n",issuedvout,i,opretlen); if ( komodo_gateway_depositremove(issuedtxid,issuedvout) == 0 ) printf("error removing deposit\n"); From 7672a1258cafece560bcbf4f2184f41d67aab99e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 13:50:18 -0300 Subject: [PATCH 202/205] test --- src/komodo.h | 4 ++++ src/komodo_gateway.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index c3b59aae9..c84179646 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -31,6 +31,7 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port); int32_t ASSETCHAINS_SHORTFLAG,NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 43000; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; +uint32_t KOMODO_INITDONE; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; uint64_t KOMODO_DEPOSIT,PENDING_KOMODO_TX; @@ -148,6 +149,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } } else fp = fopen(fname,"wb+"); printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); + KOMODO_INITDONE = (uin32_t)time(NULL); } if ( height <= 0 ) { @@ -346,6 +348,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(); + KOMODO_INITDONE = (uin32_t)time(NULL); #ifdef KOMODO_ISSUER komodo_gateway_issuer(); #else @@ -431,6 +434,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } else printf("komodo_connectblock: unexpected null pindex\n"); + KOMODO_INITDONE = (uin32_t)time(NULL); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e16bffab4..6d1b89cee 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -108,7 +108,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c portable_mutex_unlock(&Q->mutex); } if ( queue_size(&DepositsQ) == 0 && queue_size(&PendingsQ) == 0 ) - KOMODO_DEPOSIT = 0; + KOMODO_DEPOSIT = PENDING_KOMODO_TX = 0; return(n); } From 68de14defa97bb487bfa4b752e679eced3641753 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 13:52:45 -0300 Subject: [PATCH 203/205] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index c84179646..2e4d5f5e7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -31,7 +31,7 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port); int32_t ASSETCHAINS_SHORTFLAG,NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 43000; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; -uint32_t KOMODO_INITDONE; +uint32_t KOMODO_INITDONE; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; uint64_t KOMODO_DEPOSIT,PENDING_KOMODO_TX; From 63c3061098180ce8ec0bef394c7cc402397b3bce Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 13:54:01 -0300 Subject: [PATCH 204/205] test --- src/komodo.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 2e4d5f5e7..b348f70e0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -31,7 +31,7 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port); int32_t ASSETCHAINS_SHORTFLAG,NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 43000; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; -uint32_t KOMODO_INITDONE; +uint32_t KOMODO_INITDONE; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; uint64_t KOMODO_DEPOSIT,PENDING_KOMODO_TX; @@ -149,7 +149,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } } else fp = fopen(fname,"wb+"); printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); - KOMODO_INITDONE = (uin32_t)time(NULL); + KOMODO_INITDONE = (uint32_t)time(NULL); } if ( height <= 0 ) { @@ -348,7 +348,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(); - KOMODO_INITDONE = (uin32_t)time(NULL); + KOMODO_INITDONE = (uint32_t)time(NULL); #ifdef KOMODO_ISSUER komodo_gateway_issuer(); #else @@ -434,7 +434,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } else printf("komodo_connectblock: unexpected null pindex\n"); - KOMODO_INITDONE = (uin32_t)time(NULL); + KOMODO_INITDONE = (uint32_t)time(NULL); } From 91270f54879903c1a8fd3317331f6a28914d2836 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Oct 2016 14:44:16 -0300 Subject: [PATCH 205/205] test --- src/komodo_gateway.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6d1b89cee..43b1c4bbe 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -64,6 +64,11 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) printf("total numvouts.%d %.8f\n",numvouts,dstr(PENDING_KOMODO_TX)); } +int32_t komodo_check_deposit(CBlock& block) +{ + return(0); +} + void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context { struct pax_transaction *ptr;