Browse Source

signed KV

pull/4/head
jl777 7 years ago
parent
commit
6b5cfbb4b0
  1. 2
      src/komodo.h
  2. 1154
      src/komodo_curve25519.h
  3. 91
      src/komodo_gateway.h
  4. 175
      src/komodo_kv.h
  5. 8
      src/komodo_structs.h
  6. 8
      src/rpcblockchain.cpp
  7. 2
      src/rpcclient.cpp
  8. 59
      src/wallet/rpcwallet.cpp

2
src/komodo.h

@ -36,6 +36,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block);
#include "komodo_structs.h"
#include "komodo_globals.h"
#include "komodo_utils.h"
#include "komodo_curve25519.h"
#include "cJSON.c"
#include "komodo_bitcoind.h"
@ -44,6 +45,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block);
#include "komodo_notary.h"
int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char *dest);
#include "komodo_kv.h"
#include "komodo_gateway.h"
#include "komodo_events.h"

1154
src/komodo_curve25519.h

File diff suppressed because it is too large

91
src/komodo_gateway.h

@ -671,52 +671,9 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
return(0);
}
int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen)
{
struct komodo_kv *ptr; int32_t duration,retval = -1;
*heightp = -1;
*flagsp = 0;
portable_mutex_lock(&KOMODO_KV_mutex);
HASH_FIND(hh,KOMODO_KV,key,keylen,ptr);
if ( ptr != 0 )
{
duration = ((ptr->flags >> 2) + 1) * KOMODO_KVDURATION;
//printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize);
if ( current_height > (ptr->height + duration) )
{
HASH_DELETE(hh,KOMODO_KV,ptr);
if ( ptr->value != 0 )
free(ptr->value);
if ( ptr->key != 0 )
free(ptr->key);
free(ptr);
}
else
{
*heightp = ptr->height;
*flagsp = ptr->flags;
if ( (retval= ptr->valuesize) != 0 )
memcpy(value,ptr->value,retval);
}
}
portable_mutex_unlock(&KOMODO_KV_mutex);
return(retval);
}
int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize)
{
if ( refvalue == 0 && value == 0 )
return(0);
else if ( refvalue == 0 || value == 0 )
return(-1);
else if ( refvaluesize != valuesize )
return(-1);
else return(memcmp(refvalue,value,valuesize));
}
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],valuebuf[IGUANA_MAXSCRIPTSIZE]; int32_t didstats,i,j,n,kvheight,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 fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; uint32_t flags;
uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,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 fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff;
const char *typestr = "unknown";
if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 && opretbuf[0] != 'K' )
{
@ -734,51 +691,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
tokomodo = (komodo_is_issuer() == 0);
if ( opretbuf[0] == 'K' && opretlen != 40 )
{
uint16_t keylen,valuesize,newflag = 0,cmpval = 1; uint8_t *key,*valueptr; struct komodo_kv *ptr;
iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen);
iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize);
iguana_rwnum(0,&opretbuf[5],sizeof(kmdheight),&kmdheight);
iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags);
key = &opretbuf[13];
valueptr = &key[keylen];
if ( (fee= ((flags>>2)+1)*(opretlen * opretlen / keylen)) < 100000 )
fee = 100000;
// 6a164b040005006a00000000000000746573743834393333
//printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
if ( value >= fee )
{
if ( sizeof(flags)+sizeof(kmdheight)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1 == opretlen )
{
komodo_kvsearch(height,&flags,&kvheight,valuebuf,key,keylen); // expire if needed
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->key = (uint8_t *)calloc(1,keylen);
ptr->keylen = keylen;
memcpy(ptr->key,key,keylen);
newflag = 1;
HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr);
}
if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 || (cmpval= komodo_kvcmp(ptr->value,ptr->valuesize,valueptr,valuesize)) == 0 )
{
if ( cmpval != 0 )
{
if ( ptr->value != 0 )
free(ptr->value), ptr->value = 0;
if ( (ptr->valuesize= valuesize) != 0 )
{
ptr->value = (uint8_t *)calloc(1,valuesize);
memcpy(ptr->value,valueptr,valuesize);
}
}
ptr->height = kmdheight;
ptr->flags = flags;
}
portable_mutex_unlock(&KOMODO_KV_mutex);
} else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,kmdheight,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
} else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize);
komodo_kvupdate(opretbuf,opretlen,value);
}
else if ( opretbuf[0] == 'D' )
{

175
src/komodo_kv.h

@ -0,0 +1,175 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#ifndef H_KOMODOKV_H
#define H_KOMODOKV_H
int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen)
{
struct komodo_kv *ptr; int32_t duration,retval = -1;
*heightp = -1;
*flagsp = 0;
memset(pubkeyp,0,sizeof(*pubkeyp));
portable_mutex_lock(&KOMODO_KV_mutex);
HASH_FIND(hh,KOMODO_KV,key,keylen,ptr);
if ( ptr != 0 )
{
duration = ((ptr->flags >> 2) + 1) * KOMODO_KVDURATION;
//printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize);
if ( current_height > (ptr->height + duration) )
{
HASH_DELETE(hh,KOMODO_KV,ptr);
if ( ptr->value != 0 )
free(ptr->value);
if ( ptr->key != 0 )
free(ptr->key);
free(ptr);
}
else
{
*heightp = ptr->height;
*flagsp = ptr->flags;
memcpy(pubkeyp,ptr->pubkey,sizeof(*pubkeyp));
if ( (retval= ptr->valuesize) != 0 )
memcpy(value,ptr->value,retval);
}
}
portable_mutex_unlock(&KOMODO_KV_mutex);
return(retval);
}
int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize)
{
if ( refvalue == 0 && value == 0 )
return(0);
else if ( refvalue == 0 || value == 0 )
return(-1);
else if ( refvaluesize != valuesize )
return(-1);
else return(memcmp(refvalue,value,valuesize));
}
int32_t komodo_kvnumdays(uint32_t flags)
{
int32_t numdays;
if ( (numdays= ((flags>>2)&0x3ff)+1) > 365 )
numdays = 365;
return(numdays);
}
int32_t komodo_kvduration(uint32_t flags)
{
return(komodo_kvnumdays(flags) * KOMODO_KVDURATION);
}
uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen)
{
int32_t numdays; uint64_t fee;
numdays = komodo_kvnumdays(flags);
if ( (fee= (numdays*(opretlen * opretlen / keylen))) < 100000 )
fee = 100000;
return(fee);
}
void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
{
static bits256 zeroes;
uint32_t flags; bits256 pubkey,sig; int32_t i,transferflag,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,valuebuf[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr;
iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen);
iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize);
iguana_rwnum(0,&opretbuf[5],sizeof(height),&height);
iguana_rwnum(0,&opretbuf[9],sizeof(flags),&flags);
key = &opretbuf[13];
valueptr = &key[keylen];
fee = komodo_kvfee(flags,opretlen,keylen);
//printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
if ( value >= fee )
{
coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1);
if ( opretlen == coresize || opretlen == coresize+sizeof(bits256) || opretlen == coresize+2*sizeof(bits256) )
{
memset(&pubkey,0,sizeof(pubkey));
memset(&sig,0,sizeof(sig));
if ( (haspubkey= (opretlen >= coresize+sizeof(bits256))) != 0 )
{
for (i=0; i<32; i++)
((uint8_t *)&pubkey)[i] = opretbuf[coresize+i];
}
if ( (hassig= (opretlen == coresize+sizeof(bits256)*2)) != 0 )
{
for (i=0; i<32; i++)
((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(bits256)+i];
}
if ( komodo_kvsearch(&refpubkey,height,&flags,&kvheight,valuebuf,key,keylen) >= 0 )
{
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
{
if ( pubkey != refpubkey || komodo_kvsigverify(opretbuf+13,coresize-13,refpubkey,sig) < 0 )
{
printf("komodo_kvsigverify error [%d]\n",coresize-13);
return;
}
}
}
portable_mutex_lock(&KOMODO_KV_mutex);
HASH_FIND(hh,KOMODO_KV,key,keylen,ptr);
transferflag = 0;
if ( ptr != 0 )
{
if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 && memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
{
transferpubstr = (char *)&value[strlen((char *)"transfer:")];
if ( strncmp((char *)"transfer:",value,strlen((char *)"transfer:")) == 0 && is_hexstr(transferpubstr,0) == 64 )
{
transferflag = 1;
printf("transfer.(%s) to [%s]\n",key,transferpubstr);
for (i=0; i<32; i++)
((uint8_t *)&pubkey)[31-i] = _decode_hex(&transferpubstr[i*2]);
}
}
}
else if ( ptr == 0 )
{
ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr));
ptr->pubkey = pubkey;
ptr->key = (uint8_t *)calloc(1,keylen);
ptr->keylen = keylen;
memcpy(ptr->key,key,keylen);
newflag = 1;
HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr);
}
if ( transferflag != 0 )
{
ptr->pubkey = pubkey;
ptr->height = height;
}
else if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 )
{
if ( ptr->value != 0 )
free(ptr->value), ptr->value = 0;
if ( (ptr->valuesize= valuesize) != 0 )
{
ptr->value = (uint8_t *)calloc(1,valuesize);
memcpy(ptr->value,valueptr,valuesize);
}
ptr->height = height;
ptr->flags = flags;
}
portable_mutex_unlock(&KOMODO_KV_mutex);
} else printf("insufficient fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]);
} else printf("opretlen.%d mismatch keylen.%d valuesize.%d\n",opretlen,keylen,valuesize);
}
#endif

8
src/komodo_structs.h

@ -41,7 +41,13 @@
#define KOMODO_KVBINARY 2
#define KOMODO_KVDURATION 1440
struct komodo_kv { UT_hash_handle hh; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; };
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;
union _bits320 { uint8_t bytes[40]; uint16_t ushorts[20]; uint32_t uints[10]; uint64_t ulongs[5]; uint64_t txid; };
typedef union _bits320 bits320;
struct komodo_kv { UT_hash_handle hh; bits256 pubkey; 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]; };

8
src/rpcblockchain.cpp

@ -408,11 +408,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 current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,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; uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t duration,j,height,valuesize,keylen;
Object ret; uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t duration,j,height,valuesize,keylen; uint256 refpubkey; static uint256 zeroes;
if (fHelp || params.size() != 1 )
throw runtime_error("kvsearch key");
LOCK(cs_main);
@ -425,12 +425,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(chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 )
if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 )
{
std::string val; char *valuestr;
val.resize(valuesize);
valuestr = (char *)val.data();
memcpy(valuestr,value,valuesize);
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
ret.push_back(Pair("owner",refpubkey.GetHex()));
ret.push_back(Pair("height",height));
duration = ((flags >> 2) + 1) * KOMODO_KVDURATION;
ret.push_back(Pair("expiration", (int64_t)(height+duration)));

2
src/rpcclient.cpp

@ -113,7 +113,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "notaries", 1 },
{ "minerids", 1 },
{ "kvsearch", 1 },
{ "kvupdate", 3 },
{ "kvupdate", 4 },
};
class CRPCConvertTable

59
src/wallet/rpcwallet.cpp

@ -487,8 +487,12 @@ int32_t komodo_is_issuer();
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t komodo_isrealtime(int32_t *kmdheightp);
int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base);
int32_t komodo_kvsearch(int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize);
uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen);
uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 privkey);
int32_t komodo_kvduration(uint32_t flags);
uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase);
Value paxdeposit(const Array& params, bool fHelp)
{
@ -566,16 +570,27 @@ 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 duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee;
uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t coresize,haveprivkey,duration,opretlen,height; uint16_t keylen,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig;
if (fHelp || params.size() < 2 )
throw runtime_error("kvupdate key value [flags]");
throw runtime_error("kvupdate key value [flags] [passphrase]");
if (!EnsureWalletIsAvailable(fHelp))
return 0;
if ( params.size() == 3 )
if ( params.size() >= 3 )
{
flags = atoi(params[2].get_str().c_str());
//printf("flags.%d (%s)\n",flags,params[2].get_str().c_str());
} else flags = 0;
haveprivkey = 0;
memset(&sig,0,sizeof(sig));
memset(&privkey,0,sizeof(privkey));
memset(&pubkey,0,sizeof(pubkey));
if ( params.size() >= 4 )
{
privkey = komodo_kvprivkey(&pubkey,params[3].get_str().c_str());
haveprivkey = 1;
flags |= 1;
//printf("flags.%d (%s)\n",flags,params[2].get_str().c_str());
}
LOCK2(cs_main, pwalletMain->cs_wallet);
if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 )
{
@ -585,15 +600,25 @@ Value kvupdate(const Array& params, bool fHelp)
value = (uint8_t *)params[1].get_str().c_str();
valuesize = (int32_t)strlen(params[1].get_str().c_str());
}
if ( (refvaluesize= komodo_kvsearch(chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 && (tmpflags & KOMODO_KVPROTECTED) != 0 && komodo_kvcmp(refvaluesize==0?0:&keyvalue[keylen],refvaluesize,value,valuesize) != 0 )
memcpy(keyvalue,key,keylen);
if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 )
{
ret.push_back(Pair("error",(char *)"cant modify write once key"));
return ret;
if ( (tmpflags & KOMODO_KVPROTECTED) != 0 )
{
if ( refpubkey != pubkey )
{
ret.push_back(Pair("error",(char *)"cant modify write once key without passphrase"));
return ret;
}
sig = komodo_kvsig(keyvalue,keylen+valuesize,privkey);
}
}
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
height = chainActive.Tip()->nHeight;
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
ret.push_back(Pair("owner",refpubkey.GetHex()));
ret.push_back(Pair("height", (int64_t)height));
duration = ((flags >> 2) + 1) * KOMODO_KVDURATION;
duration = komodo_kvduration(flags); //((flags >> 2) + 1) * KOMODO_KVDURATION;
ret.push_back(Pair("expiration", (int64_t)(height+duration)));
ret.push_back(Pair("flags",(int64_t)flags));
ret.push_back(Pair("key",params[0].get_str()));
@ -610,14 +635,26 @@ Value kvupdate(const Array& params, bool fHelp)
memcpy(&keyvalue[12],key,keylen);
if ( value != 0 )
memcpy(&keyvalue[12 + keylen],value,valuesize);
if ( (opretlen= komodo_opreturnscript(opretbuf,'K',keyvalue,sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize)) == 40 )
coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(uint16_t)*2+keylen+valuesize);
if ( haveprivkey != 0 )
{
for (i=0; i<32; i++)
keyvalue[12 + keylen + valuesize + i] = ((uint8_t *)&pubkey)[i];
coresize += 32;
if ( refvaluesize >=0 )
{
for (i=0; i<32; i++)
keyvalue[12 + keylen + valuesize + 32 + i] = ((uint8_t *)&sig)[i];
coresize += 32;
}
}
if ( (opretlen= komodo_opreturnscript(opretbuf,'K',keyvalue,coresize)) == 40 )
opretlen++;
//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= ((flags>>2)+1)*(opretlen * opretlen / keylen)) < 100000 )
fee = 100000;
fee = komodo_kvfee(flags,opretlen,keylen);
ret.push_back(Pair("fee",(double)fee/COIN));
CBitcoinAddress destaddress(CRYPTO777_KMDADDR);
if (!destaddress.IsValid())

Loading…
Cancel
Save