This commit is contained in:
Duke Leto
2021-09-03 12:35:59 -04:00
parent ae9b87740d
commit 3d4123ee88
11 changed files with 65 additions and 90 deletions

View File

@@ -21,7 +21,7 @@
#include "hush_defs.h"
int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize)
int32_t hush_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize)
{
if ( refvalue == 0 && value == 0 )
return(0);
@@ -32,7 +32,7 @@ int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint
else return(memcmp(refvalue,value,valuesize));
}
int32_t komodo_kvnumdays(uint32_t flags)
int32_t hush_kvnumdays(uint32_t flags)
{
int32_t numdays;
if ( (numdays= ((flags>>2)&0x3ff)+1) > 365 )
@@ -40,25 +40,25 @@ int32_t komodo_kvnumdays(uint32_t flags)
return(numdays);
}
int32_t komodo_kvduration(uint32_t flags)
int32_t hush_kvduration(uint32_t flags)
{
return(komodo_kvnumdays(flags) * HUSH_KVDURATION);
return(hush_kvnumdays(flags) * HUSH_KVDURATION);
}
uint64_t komodo_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen)
uint64_t hush_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen)
{
int32_t numdays,k; uint64_t fee;
if ( (k= keylen) > 32 )
k = 32;
numdays = komodo_kvnumdays(flags);
numdays = hush_kvnumdays(flags);
if ( (fee= (numdays*(opretlen * opretlen / k))) < 100000 )
fee = 100000;
return(fee);
}
int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[DRAGON_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen)
int32_t hush_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[DRAGON_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen)
{
struct komodo_kv *ptr; int32_t duration,retval = -1;
struct hush_kv *ptr; int32_t duration,retval = -1;
*heightp = -1;
*flagsp = 0;
memset(pubkeyp,0,sizeof(*pubkeyp));
@@ -66,7 +66,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp
HASH_FIND(hh,HUSH_KV,key,keylen,ptr);
if ( ptr != 0 )
{
duration = komodo_kvduration(ptr->flags);
duration = hush_kvduration(ptr->flags);
//fprintf(stderr,"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) )
{
@@ -100,10 +100,10 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp
return(retval);
}
void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
void hush_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
{
static uint256 zeroes;
uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,refvaluesize,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,keyvalue[DRAGON_MAXSCRIPTSIZE*8]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee;
uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,refvaluesize,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,keyvalue[DRAGON_MAXSCRIPTSIZE*8]; struct hush_kv *ptr; char *transferpubstr,*tstr; uint64_t fee;
if ( SMART_CHAIN_SYMBOL[0] == 0 ) // disable KV
return;
dragon_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen);
@@ -115,11 +115,11 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
{
static uint32_t counter;
if ( ++counter < 1 )
fprintf(stderr,"komodo_kvupdate: keylen.%d + 13 > opretlen.%d, this can be ignored\n",keylen,opretlen);
fprintf(stderr,"hush_kvupdate: keylen.%d + 13 > opretlen.%d, this can be ignored\n",keylen,opretlen);
return;
}
valueptr = &key[keylen];
fee = komodo_kvfee(flags,opretlen,keylen);
fee = hush_kvfee(flags,opretlen,keylen);
//fprintf(stderr,"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 )
{
@@ -139,13 +139,13 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
((uint8_t *)&sig)[i] = opretbuf[coresize+sizeof(uint256)+i];
}
memcpy(keyvalue,key,keylen);
if ( (refvaluesize= komodo_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,&keyvalue[keylen],key,keylen)) >= 0 )
if ( (refvaluesize= hush_kvsearch((uint256 *)&refpubkey,height,&flags,&kvheight,&keyvalue[keylen],key,keylen)) >= 0 )
{
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
{
if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 )
if ( hush_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 )
{
//fprintf(stderr,"komodo_kvsigverify error [%d]\n",coresize-13);
//fprintf(stderr,"hush_kvsigverify error [%d]\n",coresize-13);
return;
}
}
@@ -169,7 +169,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value)
}
else if ( ptr == 0 )
{
ptr = (struct komodo_kv *)calloc(1,sizeof(*ptr));
ptr = (struct hush_kv *)calloc(1,sizeof(*ptr));
ptr->key = (uint8_t *)calloc(1,keylen);
ptr->keylen = keylen;
memcpy(ptr->key,key,keylen);