From e2a12abf598631bf0a45cb4be2d7b99d01daf326 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 07:39:45 -0300 Subject: [PATCH 01/36] test --- src/komodo.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0821259ea..88f801cc1 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -151,11 +151,13 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char { if ( fread(opret,1,olen,fp) != olen ) errs++; - //if ( matched != 0 ) global shared state -> global PAX - int32_t i; for (i=0; i global PAX } else printf("illegal olen.%u\n",olen); } else if ( func == 'D' ) From 66e3c53284a5cb65b014eb5cbad5c2d89d1c1214 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 08:28:11 -0300 Subject: [PATCH 02/36] test --- src/komodo_bitcoind.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a49f1a068..5e99b3924 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -510,7 +510,10 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) for (i=1; i<64; i++) { if ( komodo_minerid(height-i) == notaryid ) + { + fprintf(stderr,"ht.%d notaryid.%d already mined -i.%d\n",height,notaryid,i); return(-1); + } } return(1); } From 0b9b580674c04e4bbd80796641fba85c3b5c4147 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 09:00:25 -0300 Subject: [PATCH 03/36] 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 5e99b3924..9567ba57c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -511,7 +511,7 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) { if ( komodo_minerid(height-i) == notaryid ) { - fprintf(stderr,"ht.%d notaryid.%d already mined -i.%d\n",height,notaryid,i); + //fprintf(stderr,"ht.%d notaryid.%d already mined -i.%d\n",height,notaryid,i); return(-1); } } From 7cc6844b761f3a04eaed6c6e7d974c8b7c61ea44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 09:43:24 -0300 Subject: [PATCH 04/36] test --- src/komodo_gateway.h | 65 ++++++++++++++++++++++++++++--------------- src/rpcblockchain.cpp | 12 ++++++++ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 494fc43f0..f48910002 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -101,9 +101,27 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t } } +int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transaction *pax) +{ + int32_t i,len = 0; + for (i=0; i<32; i++) + opretbuf[len++] = ((uint8_t *)&pax->txid)[i]; + opretbuf[len++] = pax->vout & 0xff; + opretbuf[len++] = (pax->vout >> 8) & 0xff; + //printf(" issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen); + len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->komodoshis); + len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis); + len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->kmdheight),&pax->kmdheight); + len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight); + memcpy(&opretbuf[len],pax->rmd160,20), len += 20; + for (i=0; i<4; i++) + opretbuf[len++] = symbol[i]; + return(len); +} + int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) { - int32_t i,n=0,j,len,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; + struct pax_transaction p; int32_t i,n=0,j,len,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) @@ -112,33 +130,30 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t incr = 34 + (iskomodo * (sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); for (n=len=0; n>>>>>> iskomodo X: (%s) fiat %.8f kmdheight.%d other.%d\n",symbol,dstr(fiatoshis),height,otherheight); } + else + { + for (j=0; j<32; j++) + { + ((uint8_t *)&txids[n])[j] = opretbuf[len++]; + //printf("%02x",((uint8_t *)&txids[n])[j]); + } + vouts[n] = opretbuf[len++]; + vouts[n] = (opretbuf[len++] << 8) | vouts[n]; + } } } return(n); @@ -163,9 +178,9 @@ uint64_t komodo_paxtotal() return(total); } -int32_t komodo_withdraws_pending(char *opretbuf) +int32_t komodo_pending_withdraws(char *opretstr) { - struct pax_transaction *pax,*tmp; int32_t ht,len=0; uint64_t total = 0; + struct pax_transaction *pax,*tmp; uint8_t opretbuf[10000]; int32_t ht,len=0; uint64_t total = 0; if ( komodo_isrealtime(&ht) == 0 || ASSETCHAINS_SYMBOL[0] != 0 ) return(0); HASH_ITER(hh,PAX,pax,tmp) @@ -173,8 +188,14 @@ int32_t komodo_withdraws_pending(char *opretbuf) if ( pax->marked == 0 && strcmp((char *)"KMD",pax->symbol) == 0 && pax->approved == 0 ) { // add 'A' opreturn entry + if ( len == 0 ) + opretbuf[len++] = 'A'; + len += komodo_rwapproval(1,&opretbuf[len],pax); } } + if ( len > 0 ) + init_hexbytes_noT(opretstr,opretbuf,len); + else opretstr[0] = 0; return(len); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 007600a91..da5fd2fdb 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -436,6 +436,18 @@ Value notaries(const Array& params, bool fHelp) return ret; } +Value withdraws_pending(const Array& params, bool fHelp) +{ + Object ret; char opretbuf[10000*2]; int32_t opretlen; + if ( fHelp || params.size() != 0 ) + throw runtime_error("withdraws_pending needs no args\n"); + LOCK(cs_main); + if ( (opretlen= komodo_pending_withdraws(opretbuf)) > 0 ) + ret.push_back(Pair("withdraws", opretbuf)); + else ret.push_back(Pair("withdraws", (char *)"")); + return ret; +} + Value paxprice(const Array& params, bool fHelp) { if ( fHelp || params.size() < 3 || params.size() > 4 ) From 3b024dafe554f2cc388d9424ad2d0ac7a004305a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 09:44:41 -0300 Subject: [PATCH 05/36] 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 f48910002..a95c7f3ae 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -111,7 +111,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio //printf(" issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen); len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->komodoshis); len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis); - len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->kmdheight),&pax->kmdheight); + len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->height),&pax->height); len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight); memcpy(&opretbuf[len],pax->rmd160,20), len += 20; for (i=0; i<4; i++) @@ -137,7 +137,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t if ( values != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 ) { values[i] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.komodoshis : p.fiatoshis; - kmdheights[i] = p.kmdheight; + kmdheights[i] = p.height; otherheights[i] = p.otherheight; memcpy(&rmd160s[n * 20],p.rmd160,20); baseids[i] = komodo_baseid(p.symbol); From d5735262cf7877d1149f4f4fed3484a711ea705f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 09:45:27 -0300 Subject: [PATCH 06/36] 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 a95c7f3ae..20c4bb1dc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -115,7 +115,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight); memcpy(&opretbuf[len],pax->rmd160,20), len += 20; for (i=0; i<4; i++) - opretbuf[len++] = symbol[i]; + opretbuf[len++] = pax->symbol[i]; return(len); } From 9bd3a9cddcd399e2984e4029505b0bcedce0f048 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 09:48:32 -0300 Subject: [PATCH 07/36] test --- src/rpcblockchain.cpp | 6 ++++-- src/rpcclient.cpp | 1 + src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index da5fd2fdb..8bfb19629 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -436,11 +436,13 @@ Value notaries(const Array& params, bool fHelp) return ret; } -Value withdraws_pending(const Array& params, bool fHelp) +int32_t komodo_pending_withdraws(char *opretstr); + +Value paxpending(const Array& params, bool fHelp) { Object ret; char opretbuf[10000*2]; int32_t opretlen; if ( fHelp || params.size() != 0 ) - throw runtime_error("withdraws_pending needs no args\n"); + throw runtime_error("paxpending needs no args\n"); LOCK(cs_main); if ( (opretlen= komodo_pending_withdraws(opretbuf)) > 0 ) ret.push_back(Pair("withdraws", opretbuf)); diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 30142ee82..adf10ccb7 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -108,6 +108,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "z_importkey", 1 }, { "paxprice", 4 }, { "paxprices", 3 }, + { "paxpending", 3 }, { "notaries", 1 }, }; diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index e8a9958ce..4f04bdcc1 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -301,6 +301,7 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true }, { "blockchain", "verifychain", &verifychain, true }, { "blockchain", "paxprice", &paxprice, true }, + { "blockchain", "paxpending", &paxpending, true }, { "blockchain", "paxprices", &paxprices, true }, { "blockchain", "notaries", ¬aries, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 765e27747..77a4818bb 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -245,6 +245,7 @@ extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value notaries(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value paxpending(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxdeposit(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxwithdraw(const json_spirit::Array& params, bool fHelp); From 23256cca8f3465db0731e08381d227c033116eb4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:17:21 -0300 Subject: [PATCH 08/36] test --- src/komodo_bitcoind.h | 39 ++++++++++++++++++++++++++++----------- src/komodo_gateway.h | 1 + src/komodo_utils.h | 1 - 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9567ba57c..48a8b5880 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -346,6 +346,34 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) return(retstr2); } +uint256 komodo_getblockhash(int32_t height) +{ + uint256 hash; char params[128]; + memset(&hash,0,sizeof(hash)); + sprintf(params,"[%d]",height); + if ( (hexstr= komodo_issuemethod(KMDUSERPASS,"getblockhash",params,7771)) != 0 ) + { + if ( is_hexstr(hexstr,0) == 64 ) + decode_hex((uint8_t *)&hash,32,hexstr); + printf("KMD hash.%d (%s)\n",height,hexstr); + free(hexstr); + } + return(hash); +} + +uint64_t komodo_seed(int32_t height) +{ + uint256 hash; uint64_t seed = 0; CBlockIndex *pindex; + memset(&hash,0,sizeof(hash)); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + { + if ( (pindex= chainActive[height]) != 0 ) + hash = pindex->GetBlockHash(); + } else hash = komodo_getblockhash(height); + seed = arith_uint256(hash.GetHex()).GetLow64(); + return(seed); +} + uint32_t komodo_txtime(uint256 hash) { CTransaction tx; @@ -362,17 +390,6 @@ uint32_t komodo_txtime(uint256 hash) return(0); } -uint64_t komodo_seed(int32_t height) -{ - uint256 hash; uint64_t seed = 0; CBlockIndex *pindex = chainActive[height]; - if ( pindex != 0 ) - { - hash = pindex->GetBlockHash(); - seed = arith_uint256(hash.GetHex()).GetLow64(); - } - return(seed); -} - void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { char symbol[16],dest[16]; struct komodo_state *sp; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 20c4bb1dc..7c44512f9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -185,6 +185,7 @@ int32_t komodo_pending_withdraws(char *opretstr) return(0); HASH_ITER(hh,PAX,pax,tmp) { + printf("pax %s marked.%u approved.%u\n",pax->symbol,pax->marked,pax->approved); if ( pax->marked == 0 && strcmp((char *)"KMD",pax->symbol) == 0 && pax->approved == 0 ) { // add 'A' opreturn entry diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d77d8ed72..399fc4c69 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1456,7 +1456,6 @@ void komodo_args() int32_t komodo_baseid(char *origbase); extern int COINBASE_MATURITY; komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); - //if ( komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 ) COINBASE_MATURITY = 1; } ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); From 5050bd250f319aac4c0c1f7cdfd75558d8db1381 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:18:28 -0300 Subject: [PATCH 09/36] 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 48a8b5880..0e6bccf3e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -348,7 +348,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) uint256 komodo_getblockhash(int32_t height) { - uint256 hash; char params[128]; + uint256 hash; char params[128],*hexstr; memset(&hash,0,sizeof(hash)); sprintf(params,"[%d]",height); if ( (hexstr= komodo_issuemethod(KMDUSERPASS,"getblockhash",params,7771)) != 0 ) From 4767f1fcd5cb2d91603e070ba93a20c312b01578 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:22:29 -0300 Subject: [PATCH 10/36] test --- src/komodo.h | 11 ++++------- src/komodo_gateway.h | 1 + src/komodo_globals.h | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 88f801cc1..8c1445bc6 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -454,14 +454,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0); } komodo_currentheight_set(chainActive.Tip()->nHeight); - /*if ( komodo_is_issuer() != 0 ) + while ( KOMODO_PASSPORT_INITDONE == 0 ) { - while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME ) - { - fprintf(stderr,"komodo_connect.(%s) waiting for realtime RT.%u now.%u\n",ASSETCHAINS_SYMBOL,KOMODO_REALTIME,(uint32_t)time(NULL)); - sleep(30); - } - }*/ + fprintf(stderr,"komodo_connect.(%s) waiting for KOMODO_PASSPORT_INITDONE.%u\n",ASSETCHAINS_SYMBOL,KOMODO_PASSPORT_INITDONE); + sleep(3); + } KOMODO_INITDONE = (uint32_t)time(NULL); if ( pindex != 0 ) { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7c44512f9..efe743323 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -528,5 +528,6 @@ void komodo_passport_iteration() refsp->RTbufs[0][2] = 0; } refsp->RTmask = RTmask; + KOMODO_PASSPORT_INITDONE = 1; } diff --git a/src/komodo_globals.h b/src/komodo_globals.h index a4ab49acf..a17c29964 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -36,7 +36,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = 100; -int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES; +int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; uint8_t NOTARY_PUBKEY33[33]; From 16db178d7979016762bbfcdad36ae40d039f4d15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:24:11 -0300 Subject: [PATCH 11/36] 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 0e6bccf3e..b57421a5d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -351,7 +351,7 @@ uint256 komodo_getblockhash(int32_t height) uint256 hash; char params[128],*hexstr; memset(&hash,0,sizeof(hash)); sprintf(params,"[%d]",height); - if ( (hexstr= komodo_issuemethod(KMDUSERPASS,"getblockhash",params,7771)) != 0 ) + if ( (hexstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,7771)) != 0 ) { if ( is_hexstr(hexstr,0) == 64 ) decode_hex((uint8_t *)&hash,32,hexstr); From cfb7d1c2758ce251f6a719d291936307a93579df Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:27:49 -0300 Subject: [PATCH 12/36] test --- src/komodo.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 8c1445bc6..745e5f57e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -454,10 +454,13 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0); } komodo_currentheight_set(chainActive.Tip()->nHeight); - while ( KOMODO_PASSPORT_INITDONE == 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 ) { - fprintf(stderr,"komodo_connect.(%s) waiting for KOMODO_PASSPORT_INITDONE.%u\n",ASSETCHAINS_SYMBOL,KOMODO_PASSPORT_INITDONE); - sleep(3); + while ( KOMODO_PASSPORT_INITDONE == 0 ) + { + fprintf(stderr,"komodo_connect.(%s) waiting for KOMODO_PASSPORT_INITDONE.%u\n",ASSETCHAINS_SYMBOL,KOMODO_PASSPORT_INITDONE); + sleep(3); + } } KOMODO_INITDONE = (uint32_t)time(NULL); if ( pindex != 0 ) From ccf895cfcf489db5d0a5aa8605c4a5f6d2ac743e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:32:13 -0300 Subject: [PATCH 13/36] test --- src/komodo_bitcoind.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b57421a5d..619f7e556 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -348,13 +348,20 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) uint256 komodo_getblockhash(int32_t height) { - uint256 hash; char params[128],*hexstr; + uint256 hash; char params[128],*hexstr,*jsonstr; memset(&hash,0,sizeof(hash)); sprintf(params,"[%d]",height); - if ( (hexstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,7771)) != 0 ) + if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,7771)) != 0 ) { - if ( is_hexstr(hexstr,0) == 64 ) - decode_hex((uint8_t *)&hash,32,hexstr); + if ( (result= cJSON_Parse(jsonstr)) != 0 ) + { + if ( (hexstr= jstr(result,"result")) != 0 ) + { + if ( is_hexstr(hexstr,0) == 64 ) + decode_hex((uint8_t *)&hash,32,hexstr); + } + free_json(result); + } printf("KMD hash.%d (%s)\n",height,hexstr); free(hexstr); } From 9e8dd53b53656af50b51911ec509f0bc81dbf11f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:32:55 -0300 Subject: [PATCH 14/36] 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 619f7e556..ac6be5a01 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -348,7 +348,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) uint256 komodo_getblockhash(int32_t height) { - uint256 hash; char params[128],*hexstr,*jsonstr; + uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; memset(&hash,0,sizeof(hash)); sprintf(params,"[%d]",height); if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,7771)) != 0 ) From 253917191b2cbc5c7cea0a7a47513d53e5a58739 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:33:58 -0300 Subject: [PATCH 15/36] 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 ac6be5a01..9f0746f94 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -355,7 +355,7 @@ uint256 komodo_getblockhash(int32_t height) { if ( (result= cJSON_Parse(jsonstr)) != 0 ) { - if ( (hexstr= jstr(result,"result")) != 0 ) + if ( (hexstr= jstr(result,(char *)"result")) != 0 ) { if ( is_hexstr(hexstr,0) == 64 ) decode_hex((uint8_t *)&hash,32,hexstr); From 17899df4ff88736a136f967cd00b3402e1de37c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:46:56 -0300 Subject: [PATCH 16/36] test --- src/komodo.h | 4 ++-- src/komodo_gateway.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 745e5f57e..8f2858095 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -462,7 +462,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) sleep(3); } } - KOMODO_INITDONE = (uint32_t)time(NULL); + //KOMODO_INITDONE = (uint32_t)time(NULL); if ( pindex != 0 ) { height = pindex->nHeight; @@ -547,7 +547,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( pindex->nHeight == hwmheight ) komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0); } else printf("komodo_connectblock: unexpected null pindex\n"); - KOMODO_INITDONE = (uint32_t)time(NULL); + //KOMODO_INITDONE = (uint32_t)time(NULL); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index efe743323..a20b3868d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -459,6 +459,11 @@ void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; FILE *fp; int32_t baseid,isrealtime,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3]; cJSON *infoobj,*result; uint64_t RTmask = 0; + while ( KOMODO_INITDONE == 0 ) + { + fprintf(stderr,"PASSPORT iteration waiting for KOMODO_INITDONE\n"); + sleep(3); + } refsp = komodo_stateptr(symbol,dest); if ( ASSETCHAINS_SYMBOL[0] == 0 ) refid = 33; From 9e6d526c57ce2888cb022049cbadb95d5754fbf8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:52:33 -0300 Subject: [PATCH 17/36] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 8f2858095..0f46a9f71 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -99,7 +99,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) errs++; - //printf("%s load[%s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,notarized_height,notarized_hash.ToString().c_str()); + printf("%s %p %p[%d] load[%s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,sp,sp->NPOINTS,sp->NUM_NPOINTS,symbol,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); } From d3d31824e102702589091a1bb09e9109b957021a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 10:56:22 -0300 Subject: [PATCH 18/36] test --- src/komodo_structs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_structs.h b/src/komodo_structs.h index f62e5de1a..453bb35e0 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -16,11 +16,11 @@ #include "uthash.h" #include "utlist.h" -#ifdef WIN32 +/*#ifdef WIN32 #define PACKED #else #define PACKED __attribute__((packed)) -#endif +#endif*/ #define GENESIS_NBITS 0x1f00ffff #define KOMODO_MINRATIFY 7 @@ -50,7 +50,7 @@ struct komodo_event uint8_t type,reorged; char symbol[16]; uint8_t space[]; -} PACKED; +}; struct pax_transaction { From 71da283a42a39df2fac08fb8e575724550ca2aea Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 11:01:22 -0300 Subject: [PATCH 19/36] test --- src/komodo.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo.h b/src/komodo.h index 0f46a9f71..e9b193b1b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -192,8 +192,10 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { + pthread_mutex_lock(&komodo_mutex); while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; + pthread_mutex_unlock(&komodo_mutex); } else fp = fopen(fname,"wb+"); printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); KOMODO_INITDONE = (uint32_t)time(NULL); @@ -206,6 +208,7 @@ 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)); + pthread_mutex_lock(&komodo_mutex); if ( KMDheight != 0 ) { if ( KMDtimestamp != 0 ) @@ -310,6 +313,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID); } fflush(fp); + pthread_mutex_unlock(&komodo_mutex); } } From f42f928860819037276d88e4261c3e17ba086079 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 11:10:35 -0300 Subject: [PATCH 20/36] test --- src/komodo.h | 4 ---- src/komodo_events.h | 2 ++ src/komodo_notary.h | 2 ++ src/komodo_pax.h | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e9b193b1b..0f46a9f71 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -192,10 +192,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - pthread_mutex_lock(&komodo_mutex); while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; - pthread_mutex_unlock(&komodo_mutex); } else fp = fopen(fname,"wb+"); printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); KOMODO_INITDONE = (uint32_t)time(NULL); @@ -208,7 +206,6 @@ 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)); - pthread_mutex_lock(&komodo_mutex); if ( KMDheight != 0 ) { if ( KMDtimestamp != 0 ) @@ -313,7 +310,6 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID); } fflush(fp); - pthread_mutex_unlock(&komodo_mutex); } } diff --git a/src/komodo_events.h b/src/komodo_events.h index d7411737f..b5178d396 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -19,6 +19,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) { struct komodo_event *ep; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); + portable_mutex_lock(&komodo_mutex); ep = (struct komodo_event *)calloc(1,len); ep->len = len; ep->height = height; @@ -28,6 +29,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char memcpy(ep->space,data,datalen); sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events)); sp->Komodo_events[sp->Komodo_numevents++] = ep; + portable_mutex_unlock(&komodo_mutex); return(ep); } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 5cea65f95..cbfca6563 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -168,6 +168,7 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not printf("komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight); return; } + portable_mutex_lock(&komodo_mutex); sp->NPOINTS = (struct notarized_checkpoint *)realloc(sp->NPOINTS,(sp->NUM_NPOINTS+1) * sizeof(*sp->NPOINTS)); np = &sp->NPOINTS[sp->NUM_NPOINTS++]; memset(np,0,sizeof(*np)); @@ -175,6 +176,7 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not sp->NOTARIZED_HEIGHT = np->notarized_height = notarized_height; sp->NOTARIZED_HASH = np->notarized_hash = notarized_hash; sp->NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid; + portable_mutex_unlock(&komodo_mutex); } //struct komodo_state *komodo_stateptr(char *symbol,char *dest); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index a4af4b5aa..77f7c5f1f 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -285,10 +285,12 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); BTCUSD = ((double)btcusd / (1000000000. / 1000.)); CNYUSD = ((double)cnyusd / 1000000000.); + portable_mutex_lock(&komodo_mutex); 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++; + portable_mutex_unlock(&komodo_mutex); 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 be50d0e9303fbfe3298a756fd9c327f104b9128c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 11:16:40 -0300 Subject: [PATCH 21/36] 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 a20b3868d..bd151fa76 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -486,7 +486,7 @@ void komodo_passport_iteration() if ( ftell(fp) > lastpos[baseid] ) { fseek(fp,lastpos[baseid],SEEK_SET); - while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) + while ( komodo_parsestatefile(0,fp,symbol,dest) >= 0 ) ; lastpos[baseid] = ftell(fp); //printf("from.(%s) lastpos[%s] %ld\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid]); From 36ec445a12baa072b61559fa82e4fcf60e751afa Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 11:19:54 -0300 Subject: [PATCH 22/36] test --- src/komodo_events.h | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index b5178d396..828be84aa 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -18,18 +18,21 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) { - struct komodo_event *ep; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); - portable_mutex_lock(&komodo_mutex); - ep = (struct komodo_event *)calloc(1,len); - ep->len = len; - ep->height = height; - ep->type = type; - strcpy(ep->symbol,symbol); - if ( datalen != 0 ) - memcpy(ep->space,data,datalen); - sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events)); - sp->Komodo_events[sp->Komodo_numevents++] = ep; - portable_mutex_unlock(&komodo_mutex); + struct komodo_event *ep=0; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); + if ( sp != 0 ) + { + portable_mutex_lock(&komodo_mutex); + ep = (struct komodo_event *)calloc(1,len); + ep->len = len; + ep->height = height; + ep->type = type; + strcpy(ep->symbol,symbol); + if ( datalen != 0 ) + memcpy(ep->space,data,datalen); + sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events)); + sp->Komodo_events[sp->Komodo_numevents++] = ep; + portable_mutex_unlock(&komodo_mutex); + } return(ep); } @@ -124,13 +127,16 @@ void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height) void komodo_setkmdheight(struct komodo_state *sp,int32_t kmdheight,uint32_t timestamp) { - if ( kmdheight > sp->SAVEDHEIGHT ) + if ( sp != 0 ) { - sp->SAVEDHEIGHT = kmdheight; - sp->SAVEDTIMESTAMP = timestamp; + if ( kmdheight > sp->SAVEDHEIGHT ) + { + sp->SAVEDHEIGHT = kmdheight; + sp->SAVEDTIMESTAMP = timestamp; + } + if ( kmdheight > sp->CURRENT_HEIGHT ) + sp->CURRENT_HEIGHT = kmdheight; } - if ( kmdheight > sp->CURRENT_HEIGHT ) - sp->CURRENT_HEIGHT = kmdheight; } void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t height,int32_t kmdheight,uint32_t timestamp) From 807200e454bc2b5bb4cb2f3300e0aa88d760a4b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 11:22:48 -0300 Subject: [PATCH 23/36] test --- src/komodo.h | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0f46a9f71..0b79fee5e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -99,7 +99,8 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) errs++; - printf("%s %p %p[%d] load[%s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,sp,sp->NPOINTS,sp->NUM_NPOINTS,symbol,notarized_height,notarized_hash.ToString().c_str()); + if ( sp != 0 ) + printf("%s %p %p[%d] load[%s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,sp,sp->NPOINTS,sp->NUM_NPOINTS,symbol,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); } @@ -297,17 +298,19 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar else if ( height != 0 ) { //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++; - if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) ) - errs++; - if ( fwrite(&sp->NOTARIZED_HASH,1,sizeof(sp->NOTARIZED_HASH),fp) != sizeof(sp->NOTARIZED_HASH) ) - errs++; - if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) - errs++; - komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT); - //komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID); + if ( sp != 0 ) + { + fputc('N',fp); + if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) + errs++; + if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) ) + errs++; + if ( fwrite(&sp->NOTARIZED_HASH,1,sizeof(sp->NOTARIZED_HASH),fp) != sizeof(sp->NOTARIZED_HASH) ) + errs++; + if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) + errs++; + komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT); + } } fflush(fp); } From 9534c87a2e42663ca951db5a65e5dcbe4e51271e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 11:25:57 -0300 Subject: [PATCH 24/36] 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 bd151fa76..a20b3868d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -486,7 +486,7 @@ void komodo_passport_iteration() if ( ftell(fp) > lastpos[baseid] ) { fseek(fp,lastpos[baseid],SEEK_SET); - while ( komodo_parsestatefile(0,fp,symbol,dest) >= 0 ) + while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; lastpos[baseid] = ftell(fp); //printf("from.(%s) lastpos[%s] %ld\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid]); From e8433f7a918ec50e7775c57a2efb1ee6de7dd01d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 11:39:42 -0300 Subject: [PATCH 25/36] 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 a20b3868d..e91c33f85 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -108,7 +108,6 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio opretbuf[len++] = ((uint8_t *)&pax->txid)[i]; opretbuf[len++] = pax->vout & 0xff; opretbuf[len++] = (pax->vout >> 8) & 0xff; - //printf(" issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen); len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->komodoshis); len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis); len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->height),&pax->height); @@ -121,19 +120,20 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) { - struct pax_transaction p; int32_t i,n=0,j,len,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; + struct pax_transaction p; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) { opretbuf++, opretlen--; incr = 34 + (iskomodo * (sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); - for (n=len=0; n Date: Mon, 21 Nov 2016 11:47:30 -0300 Subject: [PATCH 26/36] 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 e91c33f85..58d22d72b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -126,14 +126,14 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) { opretbuf++, opretlen--; - incr = 34 + (iskomodo * (sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); + incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); for (n=0; n lastpos[baseid] ) { + printf("passport refid.%d %s fname.(%s) base.%s\n",refid,symbol,fname,base); fseek(fp,lastpos[baseid],SEEK_SET); while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; From a3f1fb69d1d29d44e83394bce901d730cfb8e1ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 11:53:46 -0300 Subject: [PATCH 27/36] test --- src/komodo_gateway.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 58d22d72b..3b3124867 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -104,6 +104,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transaction *pax) { int32_t i,len = 0; +return(0); for (i=0; i<32; i++) opretbuf[len++] = ((uint8_t *)&pax->txid)[i]; opretbuf[len++] = pax->vout & 0xff; @@ -136,11 +137,11 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t len += komodo_rwapproval(0,&opretbuf[len],&p); if ( values != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 ) { - values[i] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.komodoshis : p.fiatoshis; - kmdheights[i] = p.height; - otherheights[i] = p.otherheight; + values[n] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.komodoshis : p.fiatoshis; + kmdheights[n] = p.height; + otherheights[n] = p.otherheight; memcpy(&rmd160s[n * 20],p.rmd160,20); - baseids[i] = komodo_baseid(p.symbol); + baseids[n] = komodo_baseid(p.symbol); } printf(">>>>>>> iskomodo X: (%s) fiat %.8f kmdheight.%d other.%d\n",symbol,dstr(fiatoshis),height,otherheight); } From 1fd577185163d639aeebca969d7e9de2b105d497 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 12:00:17 -0300 Subject: [PATCH 28/36] 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 9f0746f94..8267135d9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -362,8 +362,8 @@ uint256 komodo_getblockhash(int32_t height) } free_json(result); } - printf("KMD hash.%d (%s)\n",height,hexstr); - free(hexstr); + printf("KMD hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash); + free(jsonstr); } return(hash); } From c7caa0dab26b48d4da6fac1fa38266cda13b91ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 12:03:43 -0300 Subject: [PATCH 29/36] test --- src/komodo_gateway.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3b3124867..5ee767cc7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -104,7 +104,6 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transaction *pax) { int32_t i,len = 0; -return(0); for (i=0; i<32; i++) opretbuf[len++] = ((uint8_t *)&pax->txid)[i]; opretbuf[len++] = pax->vout & 0xff; @@ -130,7 +129,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); for (n=0; n lastpos[baseid] ) { - printf("passport refid.%d %s fname.(%s) base.%s\n",refid,symbol,fname,base); + //printf("passport refid.%d %s fname.(%s) base.%s\n",refid,symbol,fname,base); fseek(fp,lastpos[baseid],SEEK_SET); while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; From 7a6cee3fde5c027ecd42f8c2bc6354d793bdf0dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 12:06:59 -0300 Subject: [PATCH 30/36] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 0b79fee5e..967386695 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -99,7 +99,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) errs++; - if ( sp != 0 ) + if ( 0 && sp != 0 ) printf("%s %p %p[%d] load[%s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,sp,sp->NPOINTS,sp->NUM_NPOINTS,symbol,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); From e9f49d50a5ded3a46e260698b272d48d88f5e696 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 12:18:20 -0300 Subject: [PATCH 31/36] test --- src/komodo_bitcoind.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8267135d9..2cdd9ba20 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -348,7 +348,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) uint256 komodo_getblockhash(int32_t height) { - uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; + uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; uint8_t revbuf[32]; memset(&hash,0,sizeof(hash)); sprintf(params,"[%d]",height); if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,7771)) != 0 ) @@ -358,7 +358,11 @@ uint256 komodo_getblockhash(int32_t height) if ( (hexstr= jstr(result,(char *)"result")) != 0 ) { if ( is_hexstr(hexstr,0) == 64 ) - decode_hex((uint8_t *)&hash,32,hexstr); + { + decode_hex(revbuf,32,hexstr); + for (i=0; i<32; i++) + ((uint8_t *)&hash)[i] = revbuf[31-i]; + } } free_json(result); } From dffceecf728aa29fd80cecd74148366001b35347 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 12:19:27 -0300 Subject: [PATCH 32/36] 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 2cdd9ba20..6878114b6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -348,7 +348,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) uint256 komodo_getblockhash(int32_t height) { - uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; uint8_t revbuf[32]; + uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; int32_t i; uint8_t revbuf[32]; memset(&hash,0,sizeof(hash)); sprintf(params,"[%d]",height); if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,7771)) != 0 ) From e97777b3b6b31d0cde02d539ed547801d970e8ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 12:27:43 -0300 Subject: [PATCH 33/36] test --- src/komodo_gateway.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5ee767cc7..522cbf3a3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -416,11 +416,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { printf("notarize %s %.8f -> %.8f kmd.%d other.%d\n",ASSETCHAINS_SYMBOL,dstr(value),dstr(komodoshis),kmdheight,height); } - else - { - printf(" %.8f -> %s withdraw already there\n",dstr(value),coinaddr); - komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height); - } + komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height); } } else if ( tokomodo != 0 && opretbuf[0] == 'A' ) From 9a2ff5ad15f6ae6ed85cf0b4c9e39272bd2071cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 12:37:36 -0300 Subject: [PATCH 34/36] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 7fe6dd34b..fffbee299 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -99,7 +99,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, } #define ASSETCHAINS_MINHEIGHT 100 -#define ROUNDROBIN_DELAY 61 +#define ROUNDROBIN_DELAY 77 extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE; extern char ASSETCHAINS_SYMBOL[16]; extern std::string NOTARY_PUBKEY; From cd26c1f3a96e36f52a88f2b31293a91ed5d48526 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 13:08:39 -0300 Subject: [PATCH 35/36] test --- src/komodo_events.h | 2 +- src/komodo_gateway.h | 24 +++++++++++++----------- src/komodo_structs.h | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index 828be84aa..0a5034a73 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -84,7 +84,7 @@ void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t heigh O.oplen = (int32_t)(opretlen + sizeof(O)); komodo_eventadd(sp,height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen); if ( sp != 0 ) - komodo_opreturn(height,value,buf,opretlen,txid,vout); + komodo_opreturn(height,value,buf,opretlen,txid,vout,symbol); } void komodo_event_undo(struct komodo_state *sp,struct komodo_event *ep) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 522cbf3a3..dd90ec80c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -51,7 +51,7 @@ struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *sp return(pax); } -void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height,int32_t otherheight) // assetchain context +void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height,int32_t otherheight,char *source) // assetchain context { struct pax_transaction *pax; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16]; sp = komodo_stateptr(str,dest); @@ -79,6 +79,8 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t pax->komodoshis = value; if ( symbol != 0 ) strcpy(pax->symbol,symbol); + if ( source != 0 ) + strcpy(pax->source,source); if ( fiatoshis != 0 ) pax->fiatoshis = fiatoshis; if ( rmd160 != 0 ) @@ -90,7 +92,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t if ( pax->marked == 0 ) { if ( addflag != 0 ) - printf("[%s] addflag.%d ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,symbol,dstr(fiatoshis),coinaddr,height,otherheight,dstr(komodo_paxtotal())); + printf("[%s] addflag.%d ADD %s %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,ASSETCHAINS_SYMBOL[0]==0?"WITHDRAW":"DEPOSIT",symbol,dstr(ASSETCHAINS_SYMBOL[0]==0?pax->komodoshis:pax->fiatoshis),pax->coinaddr,pax->height,pax->otherheight,dstr(komodo_paxtotal())); } //else printf("%p MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d otherht.%d\n",pax,pax->marked,symbol,dstr(fiatoshis),coinaddr,height,otherheight); } @@ -114,7 +116,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight); memcpy(&opretbuf[len],pax->rmd160,20), len += 20; for (i=0; i<4; i++) - opretbuf[len++] = pax->symbol[i]; + opretbuf[len++] = pax->source[i]; return(len); } @@ -353,7 +355,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above return(0); } -const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) +const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64]; struct pax_transaction *pax; const char *typestr = "unknown"; @@ -394,7 +396,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( komodo_paxfind(&space,txid,vout) == 0 ) { - komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height); + komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height,(char *)"KMD"); } else printf("duplicate deposit\n"); } } @@ -416,19 +418,19 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { printf("notarize %s %.8f -> %.8f kmd.%d other.%d\n",ASSETCHAINS_SYMBOL,dstr(value),dstr(komodoshis),kmdheight,height); } - komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height); + komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height,source); } } else if ( tokomodo != 0 && opretbuf[0] == 'A' ) { - if ( (n= komodo_issued_opreturn(base,txids,vouts,values,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,0)) > 0 ) + if ( (n= komodo_issued_opreturn(base,txids,vouts,values,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 ) { for (i=0; i= 0 ) { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); - komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i]); + komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]]); } else pax->approved = kmdheights[i]; } } @@ -442,8 +444,8 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i= 0 ) + komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,CURRENCIES[baseids[i]]); } } } diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 453bb35e0..b7d776702 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -59,7 +59,7 @@ struct pax_transaction uint64_t komodoshis,fiatoshis; int32_t marked,height,otherheight,approved; uint16_t vout; - char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; + char symbol[16],source[16],coinaddr[64]; uint8_t rmd160[20],shortflag; }; //struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; }; From f97d3439b412ddef0679a5999e718ad46ce2ca09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Nov 2016 13:19:19 -0300 Subject: [PATCH 36/36] 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 dd90ec80c..1cc0bb9cb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -187,7 +187,7 @@ int32_t komodo_pending_withdraws(char *opretstr) return(0); HASH_ITER(hh,PAX,pax,tmp) { - printf("pax %s marked.%u approved.%u\n",pax->symbol,pax->marked,pax->approved); + //printf("pax %s marked.%u approved.%u\n",pax->symbol,pax->marked,pax->approved); if ( pax->marked == 0 && strcmp((char *)"KMD",pax->symbol) == 0 && pax->approved == 0 ) { // add 'A' opreturn entry @@ -431,7 +431,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]]); - } else pax->approved = kmdheights[i]; + } + if ( (pax= komodo_paxfind(&space,txids[i],vouts[i])) != 0 ) + pax->approved = kmdheights[i]; } } }