diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7ee920089..a048a597b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -671,15 +671,17 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above return(0); } -int32_t komodo_kvsearch(int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) +int32_t komodo_kvsearch(uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen) { struct komodo_kv *ptr; int32_t retval = -1; *heightp = -1; + *flagsp = 0; portable_mutex_lock(&KOMODO_KV_mutex); HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr != 0 ) { *heightp = ptr->height; + *flagsp = ptr->flags; if ( (retval= ptr->valuesize) != 0 ) memcpy(value,ptr->value,retval); } @@ -689,7 +691,7 @@ int32_t komodo_kvsearch(int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uin 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 didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; + uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags; const char *typestr = "unknown"; if ( KOMODO_PAX == 0 ) return("nopax"); @@ -711,16 +713,18 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(kmdheight),&kmdheight); - key = &opretbuf[9]; + iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags); + key = &opretbuf[13]; value = &key[keylen]; - printf("keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); - if ( sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) + //printf("keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",keylen,valuesize,kmdheight,key[0],key[1],key[2],value[0],value[1],value[2]); + if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen ) { portable_mutex_lock(&KOMODO_KV_mutex); HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr == 0 ) { ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr)); + ptr->flags = flags; ptr->key = (uint8_t *)calloc(1,keylen); ptr->keylen = keylen; memcpy(ptr->key,key,keylen); diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 73c325de2..73194ab8e 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -37,7 +37,7 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEMED 'X' -struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; int32_t height; uint16_t keylen,valuesize; }; +struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; }; struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; }; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; }; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 50b17e171..27b074085 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -406,11 +406,11 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height); -int32_t komodo_kvsearch(int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); +int32_t komodo_kvsearch(uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); Value kvsearch(const Array& params, bool fHelp) { - Object ret; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t j,height,valuesize,keylen; + Object ret; uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t j,height,valuesize,keylen; if (fHelp || params.size() != 1 ) throw runtime_error("kvsearch key"); LOCK(cs_main); @@ -423,13 +423,14 @@ Value kvsearch(const Array& params, bool fHelp) if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); - if ( (valuesize= komodo_kvsearch(&height,value,key,keylen)) >= 0 ) + if ( (valuesize= komodo_kvsearch(&flags,&height,value,key,keylen)) >= 0 ) { std::string val; char *valuestr; val.resize(valuesize); valuestr = (char *)val.data(); memcpy(valuestr,value,valuesize); ret.push_back(Pair("height",height)); + ret.push_back(Pair("flags",flags)); ret.push_back(Pair("value",val)); ret.push_back(Pair("valuesize",valuesize)); } else ret.push_back(Pair("error",(char *)"cant find key")); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 126a98efc..29ee929bc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -404,9 +404,9 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr for (i=0; ics_wallet); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { @@ -573,6 +576,7 @@ Value kvupdate(const Array& params, bool fHelp) ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); height = chainActive.Tip()->nHeight; ret.push_back(Pair("height", (int64_t)height)); + ret.push_back(Pair("flags",flags)); ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("keylen",keylen)); if ( params.size() == 2 && params[1].get_str().c_str() != 0 ) @@ -585,13 +589,14 @@ Value kvupdate(const Array& params, bool fHelp) iguana_rwnum(1,&keyvalue[0],sizeof(keylen),&keylen); iguana_rwnum(1,&keyvalue[2],sizeof(valuesize),&valuesize); iguana_rwnum(1,&keyvalue[4],sizeof(height),&height); - memcpy(&keyvalue[8],key,keylen); + iguana_rwnum(1,&keyvalue[8],sizeof(flags),&flags); + memcpy(&keyvalue[12],key,keylen); if ( value != 0 ) - memcpy(&keyvalue[8 + keylen],value,valuesize); - opretlen = komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize); - for (i=0; i