Browse Source

test

pull/4/head
jl777 8 years ago
parent
commit
1919e9de56
  1. 14
      src/komodo_gateway.h
  2. 2
      src/komodo_structs.h
  3. 7
      src/rpcblockchain.cpp
  4. 29
      src/wallet/rpcwallet.cpp

14
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);

2
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]; };

7
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"));

29
src/wallet/rpcwallet.cpp

@ -404,9 +404,9 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr
for (i=0; i<opretlen; i++)
{
ptr[i] = opretbuf[i];
printf("%02x",ptr[i]);
//printf("%02x",ptr[i]);
}
printf(" opretbuf[%d]\n",opretlen);
//printf(" opretbuf[%d]\n",opretlen);
CRecipient opret = { opretpubkey, opretValue, false };
vecSend.push_back(opret);
}
@ -560,12 +560,15 @@ Value paxwithdraw(const Array& params, bool fHelp)
Value kvupdate(const Array& params, bool fHelp)
{
CWalletTx wtx; Object ret; uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,i,height;
uint16_t keylen,valuesize=0; uint8_t *key,*value=0; struct komodo_kv *ptr; uint64_t fee;
if (fHelp || params.size() != 2 )
CWalletTx wtx; Object ret;
uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t opretlen,height; uint16_t keylen,valuesize=0; uint8_t *key,*value=0; uint32_t flags; struct komodo_kv *ptr; uint64_t fee;
if (fHelp || params.size() < 2 )
throw runtime_error("kvupdate key value");
if (!EnsureWalletIsAvailable(fHelp))
return 0;
if ( params.size() == 3 )
flags = atoi(params[2].get_str().c_str());
else flags = 0;
LOCK2(cs_main, pwalletMain->cs_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<opretlen; i++)
printf("%02x",opretbuf[i]);
printf(" opretbuf keylen.%d valuesize.%d height.%d (%02x %02x %02x)\n",*(uint16_t *)&keyvalue[0],*(uint16_t *)&keyvalue[2],*(uint32_t *)&keyvalue[4],keyvalue[8],keyvalue[9],keyvalue[10]);
memcpy(&keyvalue[12 + keylen],value,valuesize);
opretlen = komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize);
//for (i=0; i<opretlen; i++)
// printf("%02x",opretbuf[i]);
//printf(" opretbuf keylen.%d valuesize.%d height.%d (%02x %02x %02x)\n",*(uint16_t *)&keyvalue[0],*(uint16_t *)&keyvalue[2],*(uint32_t *)&keyvalue[4],keyvalue[8],keyvalue[9],keyvalue[10]);
EnsureWalletIsUnlocked();
if ( (fee= opretlen * opretlen / keylen) < 100000 )
fee = 100000;
@ -600,7 +605,7 @@ Value kvupdate(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address");
SendMoney(destaddress.Get(),10000,false,wtx,opretbuf,opretlen,fee);
ret.push_back(Pair("txid",wtx.GetHash().GetHex()));
} else ret.push_back(Pair("error",(char *)"null key"));
} else ret.push_back(Pair("error",(char *)"null key"));
return ret;
}

Loading…
Cancel
Save