Browse Source

Merge remote-tracking branch 'remotes/upstream/dev' into dev

pull/70/head
jahway603 3 years ago
parent
commit
1bbe5a7bff
  1. 4
      src/cc/CC_made_easy.md
  2. 4
      src/cc/dapps/dappinc.h
  3. 73
      src/cc/dapps/zmigrate.c
  4. 2
      src/hush.h
  5. 6
      src/hush_curve25519.h
  6. 4
      src/hush_defs.h
  7. 2
      src/hush_gateway.h
  8. 4
      src/hush_globals.h
  9. 34
      src/hush_kv.h
  10. 28
      src/hush_notary.h
  11. 173
      src/hush_pax.h
  12. 2
      src/hush_structs.h
  13. 2
      src/hush_utils.h
  14. 2
      src/miner.cpp
  15. 2
      src/pow.cpp
  16. 2
      src/rpc/blockchain.cpp
  17. 8
      src/test-hush/test_eval_notarization.cpp
  18. 28
      src/wallet/rpcwallet.cpp
  19. 2
      src/wallet/test/wallet_tests.cpp
  20. 2
      src/wallet/wallet.cpp

4
src/cc/CC_made_easy.md

@ -17,7 +17,7 @@
How to write utxo based CryptoConditions contracts for HUSH chains
by jl777
This is not the only smart contracts methodology that is possible to build on top of OP_CHECKCRYPTOCONDITION, just the first one. All the credit for getting OP_CHECKCRYPTOCONDITION working in the Komodo codebase goes to @libscott. I am just hooking into the code that he made and tried to make it just a little easier to make new contracts.
This is not the only smart contracts methodology that is possible to build on top of OP_CHECKCRYPTOCONDITION, just the first one. All the credit for getting OP_CHECKCRYPTOCONDITION working in the Hush codebase goes to @libscott. I am just hooking into the code that he made and tried to make it just a little easier to make new contracts.
There is probably some fancy marketing name to use, but for now, I will just call it "CC contract" for short, knowing that it is not 100% technically accurate as the CryptoConditions aspect is not really the main attribute. However, the HUSH contracts were built to make the CryptoConditions codebase that was integrated into it to be more accessible.
@ -677,7 +677,7 @@ This codebase and tools in between the GUI and the rpc level will be a very good
##########
Conclusion
I hope this document has helped you understand what a Komodo utxo based CC contract is and how it is different from the other smart contracts. If you are now able to dive into the cc directory and start making your own CC contract, then I am very happy!
I hope this document has helped you understand what a Hush utxo based CC contract is and how it is different from the other smart contracts. If you are now able to dive into the cc directory and start making your own CC contract, then I am very happy!
gateways CC

4
src/cc/dapps/dappinc.h

@ -384,7 +384,7 @@ cJSON *hushdex_cli(char *clistr,char **retstrp,char *method,char *arg0,char *arg
return(retjson);
}
bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson)
bits256 hushbroadcast(char *refcoin,char *acname,cJSON *hexjson)
{
char *hexstr,*retstr,str[65]; cJSON *retjson; bits256 txid;
memset(txid.bytes,0,sizeof(txid));
@ -439,7 +439,7 @@ bits256 tokentransfer(char *refcoin,char *acname,char *tokenid,char *destpub,int
sprintf(numstr,"%llu",(long long)units);
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"tokentransfer",tokenid,destpub,numstr,"","","","")) != 0 )
{
txid = komodobroadcast(refcoin,acname,retjson);
txid = hushbroadcast(refcoin,acname,retjson);
fprintf(stderr,"tokentransfer returned (%s)\n",jprint(retjson,0));
free_json(retjson);
}

73
src/cc/dapps/zmigrate.c

@ -316,7 +316,7 @@ cJSON *get_urljson(char *url,char *fname)
char *REFCOIN_CLI;
cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2,char *arg3)
cJSON *get_hushcli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2,char *arg3)
{
long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[256];
sprintf(fname,"/tmp/zmigrate.%s",method);
@ -346,37 +346,12 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char
return(retjson);
}
bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson)
{
char *hexstr,*retstr,str[65]; cJSON *retjson; bits256 txid;
memset(txid.bytes,0,sizeof(txid));
if ( (hexstr= jstr(hexjson,"hex")) != 0 )
{
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendrawtransaction",hexstr,"","","")) != 0 )
{
//fprintf(stderr,"broadcast.(%s)\n",jprint(retjson,0));
free_json(retjson);
}
else if ( retstr != 0 )
{
if ( strlen(retstr) >= 64 )
{
retstr[64] = 0;
decode_hex(txid.bytes,32,retstr);
}
fprintf(stderr,"broadcast %s txid.(%s)\n",strlen(acname)>0?acname:refcoin,bits256_str(str,txid));
free(retstr);
}
}
return(txid);
}
bits256 sendtoaddress(char *refcoin,char *acname,char *destaddr,int64_t satoshis)
{
char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid;
memset(txid.bytes,0,sizeof(txid));
sprintf(numstr,"%.8f",(double)satoshis/SATOSHIDEN);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendtoaddress",destaddr,numstr,"","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"sendtoaddress",destaddr,numstr,"","")) != 0 )
{
fprintf(stderr,"unexpected sendrawtransaction json.(%s)\n",jprint(retjson,0));
free_json(retjson);
@ -397,7 +372,7 @@ bits256 sendtoaddress(char *refcoin,char *acname,char *destaddr,int64_t satoshis
int32_t get_coinheight(char *refcoin,char *acname)
{
cJSON *retjson; char *retstr; int32_t height=0;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockchaininfo","","","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"getblockchaininfo","","","","")) != 0 )
{
height = jint(retjson,"blocks");
free_json(retjson);
@ -415,7 +390,7 @@ bits256 get_coinblockhash(char *refcoin,char *acname,int32_t height)
cJSON *retjson; char *retstr,heightstr[32]; bits256 hash;
memset(hash.bytes,0,sizeof(hash));
sprintf(heightstr,"%d",height);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockhash",heightstr,"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"getblockhash",heightstr,"","","")) != 0 )
{
fprintf(stderr,"unexpected blockhash json.(%s)\n",jprint(retjson,0));
free_json(retjson);
@ -436,7 +411,7 @@ bits256 get_coinmerkleroot(char *refcoin,char *acname,bits256 blockhash)
{
cJSON *retjson; char *retstr,str[65]; bits256 merkleroot;
memset(merkleroot.bytes,0,sizeof(merkleroot));
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","","")) != 0 )
{
merkleroot = jbits256(retjson,"merkleroot");
//fprintf(stderr,"got merkleroot.(%s)\n",bits256_str(str,merkleroot));
@ -474,7 +449,7 @@ int32_t get_coinheader(char *refcoin,char *acname,bits256 *blockhashp,bits256 *m
cJSON *get_rawmempool(char *refcoin,char *acname)
{
cJSON *retjson; char *retstr;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawmempool","","","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"getrawmempool","","","","")) != 0 )
{
//printf("mempool.(%s)\n",jprint(retjson,0));
return(retjson);
@ -493,7 +468,7 @@ cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr)
if ( refcoin[0] != 0 && strcmp(refcoin,"HUSH3") != 0 )
printf("warning: assumes %s has addressindex enabled\n",refcoin);
sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","","")) != 0 )
{
//printf("addressutxos.(%s)\n",jprint(retjson,0));
return(retjson);
@ -509,7 +484,7 @@ cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr)
cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid)
{
cJSON *retjson; char *retstr,str[65];
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","","")) != 0 )
{
return(retjson);
}
@ -524,7 +499,7 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid)
cJSON *get_listunspent(char *refcoin,char *acname)
{
cJSON *retjson; char *retstr,str[65];
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","","","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"listunspent","","","","")) != 0 )
{
return(retjson);
}
@ -539,7 +514,7 @@ cJSON *get_listunspent(char *refcoin,char *acname)
cJSON *z_listunspent(char *refcoin,char *acname)
{
cJSON *retjson; char *retstr,str[65];
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_listunspent","","","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"z_listunspent","","","","")) != 0 )
{
return(retjson);
}
@ -554,7 +529,7 @@ cJSON *z_listunspent(char *refcoin,char *acname)
cJSON *z_listoperationids(char *refcoin,char *acname)
{
cJSON *retjson; char *retstr,str[65];
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_listoperationids","","","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"z_listoperationids","","","","")) != 0 )
{
return(retjson);
}
@ -570,7 +545,7 @@ cJSON *z_getoperationstatus(char *refcoin,char *acname,char *opid)
{
cJSON *retjson; char *retstr,str[65],params[512];
sprintf(params,"'[\"%s\"]'",opid);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getoperationstatus",params,"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"z_getoperationstatus",params,"","","")) != 0 )
{
//printf("got status (%s)\n",jprint(retjson,0));
return(retjson);
@ -587,7 +562,7 @@ cJSON *z_getoperationresult(char *refcoin,char *acname,char *opid)
{
cJSON *retjson; char *retstr,str[65],params[512];
sprintf(params,"'[\"%s\"]'",opid);
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getoperationresult",params,"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"z_getoperationresult",params,"","","")) != 0 )
{
return(retjson);
}
@ -602,7 +577,7 @@ cJSON *z_getoperationresult(char *refcoin,char *acname,char *opid)
int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* compare)
{
cJSON *retjson; char *retstr; int32_t res=0;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 )
{
if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1;
free_json(retjson);
@ -618,7 +593,7 @@ int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* comp
int32_t z_validateaddress(char *refcoin,char *acname,char *depositaddr, char *compare)
{
cJSON *retjson; char *retstr; int32_t res=0;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_validateaddress",depositaddr,"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"z_validateaddress",depositaddr,"","","")) != 0 )
{
if (is_cJSON_True(jobj(retjson,compare)) != 0 )
res=1;
@ -635,7 +610,7 @@ int32_t z_validateaddress(char *refcoin,char *acname,char *depositaddr, char *co
int64_t z_getbalance(char *refcoin,char *acname,char *coinaddr)
{
cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getbalance",coinaddr,"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"z_getbalance",coinaddr,"","","")) != 0 )
{
fprintf(stderr,"z_getbalance.(%s) %s returned json!\n",refcoin,acname);
free_json(retjson);
@ -656,7 +631,7 @@ int32_t z_exportkey(char *privkey,char *refcoin,char *acname,char *zaddr)
{
cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0;
privkey[0] = 0;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_exportkey",zaddr,"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"z_exportkey",zaddr,"","","")) != 0 )
{
fprintf(stderr,"z_exportkey.(%s) %s returned json!\n",refcoin,acname);
free_json(retjson);
@ -675,7 +650,7 @@ int32_t z_exportkey(char *privkey,char *refcoin,char *acname,char *zaddr)
int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname)
{
cJSON *retjson; char *retstr; int64_t amount=0; int32_t retval = -1;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getnewaddress","","","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"getnewaddress","","","","")) != 0 )
{
fprintf(stderr,"getnewaddress.(%s) %s returned json!\n",refcoin,acname);
free_json(retjson);
@ -692,7 +667,7 @@ int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname)
int32_t z_getnewaddress(char *coinaddr,char *refcoin,char *acname,char *typestr)
{
cJSON *retjson; char *retstr; int64_t amount=0; int32_t retval = -1;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getnewaddress",typestr,"","","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"z_getnewaddress",typestr,"","","")) != 0 )
{
fprintf(stderr,"z_getnewaddress.(%s) %s returned json!\n",refcoin,acname);
free_json(retjson);
@ -764,7 +739,7 @@ int64_t find_sprout_amount(char *coinstr,char *zcaddr)
void importaddress(char *refcoin,char *acname,char *depositaddr)
{
cJSON *retjson; char *retstr;
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"importaddress",depositaddr,"","true","")) != 0 )
if ( (retjson= get_hushcli(refcoin,&retstr,acname,"importaddress",depositaddr,"","true","")) != 0 )
{
printf("importaddress.(%s)\n",jprint(retjson,0));
free_json(retjson);
@ -782,7 +757,7 @@ int32_t z_sendmany(char *opidstr,char *coinstr,char *acname,char *srcaddr,char *
sprintf(params,"'[{\"address\":\"%s\",\"amount\":%.8f}]'",destaddr,dstr(amount));
sprintf(addr,"\"%s\"",srcaddr);
printf("z_sendmany from.(%s) -> %s\n",srcaddr,params);
if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_sendmany",addr,params,"","")) != 0 )
if ( (retjson= get_hushcli(coinstr,&retstr,acname,"z_sendmany",addr,params,"","")) != 0 )
{
printf("unexpected json z_sendmany.(%s)\n",jprint(retjson,0));
free_json(retjson);
@ -801,7 +776,7 @@ int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr
{
cJSON *retjson; char *retstr,addr[128],*opstr; int32_t retval = -1;
sprintf(addr,"[\\\"ANY_SPROUT\\\"]");
if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_mergetoaddress",addr,destaddr,"","")) != 0 )
if ( (retjson= get_hushcli(coinstr,&retstr,acname,"z_mergetoaddress",addr,destaddr,"","")) != 0 )
{
if ( (opstr= jstr(retjson,"opid")) != 0 )
strcpy(opidstr,opstr);
@ -1044,8 +1019,8 @@ int32_t itemvalid(char *refcoin,int64_t *refundedp,int64_t *waitingp,struct clai
*refundedp = *waitingp = 0;
if ( item->refundvalue < 0 )
return(-1);
// change "kmd" -> %s, tolowerstr(refcoin)
sprintf(url,"https://kmd.explorer.dexstats.info/insight-api-komodo/addr/%s",item->destaddr);
sprintf(url,"https://explorer.hush.is/api/addr/%s",item->destaddr);
if ( (retstr= send_curl(url,"/tmp/itemvalid")) != 0 )
{
if ( (curljson= cJSON_Parse(retstr)) != 0 )

2
src/hush.h

@ -944,7 +944,7 @@ int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block)
{
memset(&txhash,0,sizeof(txhash));
hush_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0,zero,0);
printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height);
printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+HUSH_DPOW_GAP/2)/HUSH_DPOW_GAP)+1)*HUSH_DPOW_GAP,height);
} else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries);
}
}

6
src/hush_curve25519.h

@ -955,14 +955,14 @@ uint64_t conv_NXTpassword(unsigned char *mysecret,unsigned char *mypublic,uint8_
return(addr);
}
uint256 komodo_kvprivkey(uint256 *pubkeyp,char *passphrase)
uint256 hush_kvprivkey(uint256 *pubkeyp,char *passphrase)
{
uint256 privkey;
conv_NXTpassword((uint8_t *)&privkey,(uint8_t *)pubkeyp,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
return(privkey);
}
uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 _privkey)
uint256 hush_kvsig(uint8_t *buf,int32_t len,uint256 _privkey)
{
bits256 sig,hash,otherpub,checksig,pubkey,privkey; uint256 usig;
memcpy(&privkey,&_privkey,sizeof(privkey));
@ -984,7 +984,7 @@ uint256 komodo_kvsig(uint8_t *buf,int32_t len,uint256 _privkey)
return(usig);
}
int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig)
int32_t hush_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig)
{
bits256 hash,checksig,pubkey; static uint256 zeroes;
memcpy(&pubkey,&_pubkey,sizeof(pubkey));

4
src/hush_defs.h

@ -23,7 +23,7 @@
#define HUSH_EARLYTXID_HEIGHT 100
#define ASSETCHAINS_MINHEIGHT 128
#define ASSETCHAINS_MAX_ERAS 7
#define KOMODO_ELECTION_GAP 2000
#define HUSH_DPOW_GAP 2000
#define ROUNDROBIN_DELAY 61
#define HUSH_SMART_CHAIN_MAXLEN 65
#define HUSH_LIMITED_NETWORKSIZE 4
@ -539,7 +539,7 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas
int32_t hush_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
int32_t hush_minerids(uint8_t *minerids,int32_t height,int32_t width);
int32_t komodo_kvsearch(uint256 *refpubkeyp,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 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[DRAGON_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
uint32_t hush_blocktime(uint256 hash);
int32_t hush_longestchain();

2
src/hush_gateway.h

@ -846,7 +846,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
tokomodo = (hush_is_issuer() == 0);
if ( opretbuf[0] == 'K' && opretlen != 40 )
{
komodo_kvupdate(opretbuf,opretlen,value);
hush_kvupdate(opretbuf,opretlen,value);
return("kv");
}
else if ( SMART_CHAIN_SYMBOL[0] == 0 && HUSH_PAX == 0 )

4
src/hush_globals.h

@ -34,7 +34,7 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max);
int32_t hush_checkvout(int32_t vout,int32_t k,int32_t indallvouts);
pthread_mutex_t hush_mutex;
#define KOMODO_ELECTION_GAP 2000 //((SMART_CHAIN_SYMBOL[0] == 0) ? 2000 : 100)
#define HUSH_DPOW_GAP 2000 //((SMART_CHAIN_SYMBOL[0] == 0) ? 2000 : 100)
#define HUSH_SMART_CHAIN_MAXLEN 65
struct pax_transaction *PAX;
@ -103,7 +103,7 @@ int32_t HUSH_TESTNODE, HUSH_SNAPSHOT_INTERVAL;
CScript HUSH_EARLYTXID_SCRIPTPUB;
int32_t ASSETCHAINS_EARLYTXIDCONTRACT;
std::map <std::int8_t, int32_t> mapHeightEvalActivate;
struct komodo_kv *HUSH_KV;
struct hush_kv *HUSH_KV;
pthread_mutex_t HUSH_KV_mutex,HUSH_CC_mutex;
#define MAX_CURRENCIES 32

34
src/hush_kv.h

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

28
src/hush_notary.h

@ -143,17 +143,17 @@ void hush_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num)
static int32_t hwmheight;
int32_t k,i,htind,height; struct knotary_entry *kp; struct knotaries_entry N;
if ( Pubkeys == 0 )
Pubkeys = (struct knotaries_entry *)calloc(1 + (HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP),sizeof(*Pubkeys));
Pubkeys = (struct knotaries_entry *)calloc(1 + (HUSH_MAXBLOCKS / HUSH_DPOW_GAP),sizeof(*Pubkeys));
memset(&N,0,sizeof(N));
if ( origheight > 0 )
{
height = (origheight + KOMODO_ELECTION_GAP/2);
height /= KOMODO_ELECTION_GAP;
height = ((height + 1) * KOMODO_ELECTION_GAP);
htind = (height / KOMODO_ELECTION_GAP);
if ( htind >= HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP )
htind = (HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1;
//printf("htind.%d activation %d from %d vs %d | hwmheight.%d %s\n",htind,height,origheight,(((origheight+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,hwmheight,SMART_CHAIN_SYMBOL);
height = (origheight + HUSH_DPOW_GAP/2);
height /= HUSH_DPOW_GAP;
height = ((height + 1) * HUSH_DPOW_GAP);
htind = (height / HUSH_DPOW_GAP);
if ( htind >= HUSH_MAXBLOCKS / HUSH_DPOW_GAP )
htind = (HUSH_MAXBLOCKS / HUSH_DPOW_GAP) - 1;
//printf("htind.%d activation %d from %d vs %d | hwmheight.%d %s\n",htind,height,origheight,(((origheight+HUSH_DPOW_GAP/2)/HUSH_DPOW_GAP)+1)*HUSH_DPOW_GAP,hwmheight,SMART_CHAIN_SYMBOL);
} else htind = 0;
pthread_mutex_lock(&hush_mutex);
for (k=0; k<num; k++)
@ -166,11 +166,11 @@ void hush_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num)
{
for (i=0; i<33; i++)
printf("%02x",pubkeys[k][i]);
printf(" notarypubs.[%d] ht.%d active at %d\n",k,origheight,htind*KOMODO_ELECTION_GAP);
printf(" notarypubs.[%d] ht.%d active at %d\n",k,origheight,htind*HUSH_DPOW_GAP);
}
}
N.numnotaries = num;
for (i=htind; i<HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP; i++)
for (i=htind; i<HUSH_MAXBLOCKS / HUSH_DPOW_GAP; i++)
{
if ( Pubkeys[i].height != 0 && origheight < hwmheight )
{
@ -178,7 +178,7 @@ void hush_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num)
break;
}
Pubkeys[i] = N;
Pubkeys[i].height = i * KOMODO_ELECTION_GAP;
Pubkeys[i].height = i * HUSH_DPOW_GAP;
}
pthread_mutex_unlock(&hush_mutex);
if ( origheight > hwmheight )
@ -207,9 +207,9 @@ int32_t hush_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,ui
return(-1);
if ( Pubkeys == 0 )
hush_init(0);
htind = height / KOMODO_ELECTION_GAP;
if ( htind >= HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP )
htind = (HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1;
htind = height / HUSH_DPOW_GAP;
if ( htind >= HUSH_MAXBLOCKS / HUSH_DPOW_GAP )
htind = (HUSH_MAXBLOCKS / HUSH_DPOW_GAP) - 1;
pthread_mutex_lock(&hush_mutex);
HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp);
pthread_mutex_unlock(&hush_mutex);

173
src/hush_pax.h

@ -195,45 +195,6 @@ double PAX_BTCUSD(int32_t height,uint32_t btcusd)
return(BTCUSD);
}
int32_t dpow_readprices(int32_t height,uint8_t *data,uint32_t *timestampp,double *KMDBTCp,double *BTCUSDp,double *CNYUSDp,uint32_t *pvals)
{
uint32_t kmdbtc,btcusd,cnyusd; int32_t i,n,nonz,len = 0;
if ( data[0] == 'P' && data[5] == 35 )
data++;
len += dragon_rwnum(0,&data[len],sizeof(uint32_t),(void *)timestampp);
len += dragon_rwnum(0,&data[len],sizeof(uint32_t),(void *)&n);
if ( n != 35 )
{
printf("dpow_readprices illegal n.%d\n",n);
return(-1);
}
len += dragon_rwnum(0,&data[len],sizeof(uint32_t),(void *)&kmdbtc); // /= 1000
len += dragon_rwnum(0,&data[len],sizeof(uint32_t),(void *)&btcusd); // *= 1000
len += dragon_rwnum(0,&data[len],sizeof(uint32_t),(void *)&cnyusd);
*KMDBTCp = ((double)kmdbtc / (1000000000. * 1000.));
*BTCUSDp = PAX_BTCUSD(height,btcusd);
*CNYUSDp = ((double)cnyusd / 1000000000.);
for (i=nonz=0; i<n-3; i++)
{
if ( pvals[i] != 0 )
nonz++;
//else if ( nonz != 0 )
// printf("pvals[%d] is zero\n",i);
len += dragon_rwnum(0,&data[len],sizeof(uint32_t),(void *)&pvals[i]);
//printf("%u ",pvals[i]);
}
/*if ( nonz < n-3 )
{
//printf("nonz.%d n.%d retval -1\n",nonz,n);
return(-1);
}*/
pvals[i++] = kmdbtc;
pvals[i++] = btcusd;
pvals[i++] = cnyusd;
//printf("OP_RETURN prices\n");
return(n);
}
int32_t PAX_pubkey(int32_t rwflag,uint8_t *pubkey33,uint8_t *addrtypep,uint8_t rmd160[20],char fiat[4],uint8_t *shortflagp,int64_t *fiatoshisp)
{
if ( rwflag != 0 )
@ -269,33 +230,6 @@ double PAX_val(uint32_t pval,int32_t baseid)
void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals)
{
int32_t i,nonz; uint32_t kmdbtc,btcusd,cnyusd; double KMDBTC,BTCUSD,CNYUSD;
if ( numpvals >= 35 )
{
for (nonz=i=0; i<32; i++)
{
if ( pvals[i] != 0 )
nonz++;
//printf("%u ",pvals[i]);
}
if ( nonz == 32 )
{
kmdbtc = pvals[i++];
btcusd = pvals[i++];
cnyusd = pvals[i++];
KMDBTC = ((double)kmdbtc / (1000000000. * 1000.));
BTCUSD = PAX_BTCUSD(height,btcusd);
CNYUSD = ((double)cnyusd / 1000000000.);
portable_mutex_lock(&hush_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(&hush_mutex);
if ( 0 )
printf("OP_RETURN.%d HUSH %.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);
}
}
}
uint64_t komodo_paxcorrelation(uint64_t *votes,int32_t numvotes,uint64_t seed)
@ -360,80 +294,6 @@ uint64_t komodo_paxcorrelation(uint64_t *votes,int32_t numvotes,uint64_t seed)
return(sum);
}
uint64_t komodo_paxcalc(int32_t height,uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t basevolume,uint64_t refkmdbtc,uint64_t refbtcusd)
{
uint32_t pvalb,pvalr; double BTCUSD; uint64_t price,kmdbtc,btcusd,usdvol,baseusd,usdkmd,baserel,ranked[32];
if ( basevolume > HUSH_PAXMAX )
{
printf("paxcalc overflow %.8f\n",dstr(basevolume));
return(0);
}
if ( (pvalb= pvals[baseid]) != 0 )
{
if ( relid == MAX_CURRENCIES )
{
if ( height < 236000 )
{
if ( kmdbtc == 0 )
kmdbtc = pvals[MAX_CURRENCIES];
if ( btcusd == 0 )
btcusd = pvals[MAX_CURRENCIES + 1];
}
else
{
if ( (kmdbtc= pvals[MAX_CURRENCIES]) == 0 )
kmdbtc = refkmdbtc;
if ( (btcusd= pvals[MAX_CURRENCIES + 1]) == 0 )
btcusd = refbtcusd;
}
if ( kmdbtc < 25000000 )
kmdbtc = 25000000;
if ( pvals[USD] != 0 && kmdbtc != 0 && btcusd != 0 )
{
baseusd = (((uint64_t)pvalb * 1000000000) / pvals[USD]);
usdvol = komodo_paxvol(basevolume,baseusd);
usdkmd = ((uint64_t)kmdbtc * 1000000000) / btcusd;
if ( height >= 236000-10 )
{
BTCUSD = PAX_BTCUSD(height,btcusd);
if ( height < BTCFACTOR_HEIGHT || (height < 500000 && BTCUSD > 20000) )
usdkmd = ((uint64_t)kmdbtc * btcusd) / 1000000000;
else usdkmd = ((uint64_t)kmdbtc * btcusd) / 10000000;
///if ( height >= BTCFACTOR_HEIGHT && BTCUSD >= 43 )
// usdkmd = ((uint64_t)kmdbtc * btcusd) / 10000000;
//else usdkmd = ((uint64_t)kmdbtc * btcusd) / 1000000000;
price = ((uint64_t)10000000000 * MINDENOMS[USD] / MINDENOMS[baseid]) / komodo_paxvol(usdvol,usdkmd);
//fprintf(stderr,"ht.%d %.3f kmdbtc.%llu btcusd.%llu base -> USD %llu, usdkmd %llu usdvol %llu -> %llu\n",height,BTCUSD,(long long)kmdbtc,(long long)btcusd,(long long)baseusd,(long long)usdkmd,(long long)usdvol,(long long)(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100)));
//fprintf(stderr,"usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %llu %llu\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,(long long)(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100)),(long long)price);
//fprintf(stderr,"usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %llu\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,(long long)(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100)));
} else price = (MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100));
return(price);
} //else printf("zero val in KMD conv %llu %llu %llu\n",(long long)pvals[USD],(long long)kmdbtc,(long long)btcusd);
}
else if ( baseid == relid )
{
if ( baseid != MAX_CURRENCIES )
{
pax_rank(ranked,pvals);
//printf("%s M1 percentage %.8f\n",CURRENCIES[baseid],dstr(10 * ranked[baseid]));
return(10 * ranked[baseid]); // scaled percentage of M1 total
} else return(basevolume);
}
else if ( (pvalr= pvals[relid]) != 0 )
{
baserel = ((uint64_t)pvalb * 1000000000) / pvalr;
//printf("baserel.%lld %lld %lld %.8f %.8f\n",(long long)baserel,(long long)MINDENOMS[baseid],(long long)MINDENOMS[relid],dstr(MINDENOMS[baseid]/MINDENOMS[relid]),dstr(MINDENOMS[relid]/MINDENOMS[baseid]));
if ( MINDENOMS[baseid] > MINDENOMS[relid] )
basevolume /= (MINDENOMS[baseid] / MINDENOMS[relid]);
else if ( MINDENOMS[baseid] < MINDENOMS[relid] )
basevolume *= (MINDENOMS[relid] / MINDENOMS[baseid]);
return(komodo_paxvol(basevolume,baserel));
}
else printf("null pval for %s\n",CURRENCIES[relid]);
} else printf("null pval for %s\n",CURRENCIES[baseid]);
return(0);
}
uint64_t komodo_paxpriceB(uint64_t seed,int32_t height,char *base,char *rel,uint64_t basevolume)
{
return 0;
@ -451,40 +311,9 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas
void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen)
{
double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; uint256 zero;
numpvals = dpow_readprices(height,pricefeed,&timestamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals);
memset(&zero,0,sizeof(zero));
hush_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0,0,0,0,zero,0);
if ( 0 )
{
int32_t i;
for (i=0; i<numpvals; i++)
printf("%u ",pvals[i]);
printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d kmdbtc %.8f BTCUSD %.8f CNYUSD %.8f\n",height,numpvals,opretlen,KMDBTC,BTCUSD,CNYUSD);
}
}
uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis)
{
uint8_t shortflag = 0; char base[4]; int32_t i,baseid; uint8_t addrtype,rmd160[20]; int64_t komodoshis = 0;
*seedp = hush_seed(height);
if ( (baseid= hush_baseid(origbase)) < 0 || baseid == MAX_CURRENCIES )
{
if ( 0 && origbase[0] != 0 )
printf("[%s] PAX_fiatdest illegal base.(%s)\n",SMART_CHAIN_SYMBOL,origbase);
return(0);
}
for (i=0; i<3; i++)
base[i] = toupper(origbase[i]);
base[i] = 0;
if ( fiatoshis < 0 )
shortflag = 1, fiatoshis = -fiatoshis;
komodoshis = komodo_paxprice(seedp,height,base,(char *)"KMD",(uint64_t)fiatoshis);
//printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f seed.%llx\n",height,base,(double)fiatoshis/COIN,(double)komodoshis/COIN,(long long)*seedp);
if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 )
{
PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,tokomodo != 0 ? &komodoshis : &fiatoshis);
bitcoin_address(destaddr,HUSH_PUBTYPE,pubkey33,33);
}
return(komodoshis);
return 0;
}

2
src/hush_structs.h

@ -56,7 +56,7 @@
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 hush_kv { UT_hash_handle hh; bits256 pubkey; uint8_t *key,*value; int32_t height; uint32_t flags; uint16_t keylen,valuesize; };
struct hush_event_notarized { uint256 blockhash,desttxid,MoM; int32_t notarizedheight,MoMdepth; char dest[16]; };
struct hush_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; };

2
src/hush_utils.h

@ -1810,7 +1810,7 @@ void hush_args(char *argv0)
vector<string> HUSH_nodes= {"node1.hush.is","node2.hush.is","node3.hush.is",
"node4.hush.is","node5.hush.is","node6.hush.is",
"node7.hush.is","node8.hush.is"};
"node7.hush.is","node8.hush.is","node1.hush.land", "node2.hush.land"};
vector<string> more_nodes = mapMultiArgs["-addnode"];
if (more_nodes.size() > 0) {
fprintf(stderr,"%s: Adding %lu more nodes via custom -addnode arguments\n", __func__, more_nodes.size() );

2
src/miner.cpp

@ -1183,7 +1183,7 @@ void static BitcoinMiner()
if ( SMART_CHAIN_SYMBOL[0] == 0 && notaryid >= 0 )
{
j = 65;
if ( (Mining_height >= 235300 && Mining_height < 236000) || (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 || Mining_height > 1000000 )
if ( (Mining_height >= 235300 && Mining_height < 236000) || (Mining_height % HUSH_DPOW_GAP) > 64 || (Mining_height % HUSH_DPOW_GAP) == 0 || Mining_height > 1000000 )
{
int32_t dispflag = 0;
if ( notaryid <= 3 || notaryid == 32 || (notaryid >= 43 && notaryid <= 45) || notaryid == 51 || notaryid == 52 || notaryid == 56 || notaryid == 57 )

2
src/pow.cpp

@ -677,7 +677,7 @@ bool hush_checkopret(CBlock *pblock, CScript &merkleroot);
CScript hush_makeopret(CBlock *pblock, bool fNew);
extern int32_t HUSH_CHOSEN_ONE;
extern char SMART_CHAIN_SYMBOL[HUSH_SMART_CHAIN_MAXLEN];
#define KOMODO_ELECTION_GAP 2000
#define HUSH_DPOW_GAP 2000
int32_t hush_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height);
int32_t HUSH_LOADINGBLOCKS = 1;

2
src/rpc/blockchain.cpp

@ -893,7 +893,7 @@ UniValue kvsearch(const UniValue& params, bool fHelp, const CPubKey& mypk)
if ( keylen < sizeof(key) )
{
memcpy(key,params[0].get_str().c_str(),keylen);
if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->GetHeight(),&flags,&height,value,key,keylen)) >= 0 )
if ( (valuesize= hush_kvsearch(&refpubkey,chainActive.LastTip()->GetHeight(),&flags,&height,value,key,keylen)) >= 0 )
{
std::string val; char *valuestr;
val.resize(valuesize);

8
src/test-hush/test_eval_notarization.cpp

@ -3,7 +3,6 @@
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
#include <cryptoconditions.h>
#include <gtest/gtest.h>
#include "cc/betprotocol.h"
#include "cc/eval.h"
#include "base58.h"
@ -14,16 +13,12 @@
#include "primitives/transaction.h"
#include "script/interpreter.h"
#include "script/serverchecker.h"
#include "testutils.h"
extern int32_t hush_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
namespace TestEvalNotarization {
class EvalMock : public Eval
{
public:
@ -86,7 +81,6 @@ namespace TestEvalNotarization {
}
// https://kmd.explorer.supernet.org/tx/5b8055d37cff745a404d1ae45e21ffdba62da7b28ed6533c67468d7379b20bae
// inputs have been dropped
static auto rawNotaryTx = "01000000000290460100000000002321020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9ac0000000000000000506a4c4dae8e0f3e6e5de498a072f5967f3c418c4faba5d56ac8ce17f472d029ef3000008f2e0100424f545300050ba773f0bc31da5839fc7cb9bd7b87f3b765ca608e5cf66785a466659b28880500000000000000";
CTransaction notaryTx;
@ -201,6 +195,4 @@ TEST(TestEvalNotarization, testInvalidNotarizationInputNotCheckSig)
ASSERT_FALSE(eval.GetNotarizationData(notary.GetHash(), data));
}
} /* namespace TestEvalNotarization */

28
src/wallet/rpcwallet.cpp

@ -616,19 +616,19 @@ int32_t hush_is_issuer();
int32_t dragon_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t hush_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(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[DRAGON_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);
int32_t komodo_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig);
int32_t hush_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[DRAGON_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
int32_t hush_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize);
uint64_t hush_kvfee(uint32_t flags,int32_t opretlen,int32_t keylen);
uint256 hush_kvsig(uint8_t *buf,int32_t len,uint256 privkey);
int32_t hush_kvduration(uint32_t flags);
uint256 hush_kvprivkey(uint256 *pubkeyp,char *passphrase);
int32_t hush_kvsigverify(uint8_t *buf,int32_t len,uint256 _pubkey,uint256 sig);
UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
static uint256 zeroes;
CWalletTx wtx; UniValue ret(UniValue::VOBJ);
uint8_t keyvalue[DRAGON_MAXSCRIPTSIZE*8],opretbuf[DRAGON_MAXSCRIPTSIZE*8]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen=0,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags,n; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig;
uint8_t keyvalue[DRAGON_MAXSCRIPTSIZE*8],opretbuf[DRAGON_MAXSCRIPTSIZE*8]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen=0,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags,n; struct hush_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig;
if (fHelp || params.size() < 3 )
throw runtime_error(
"kvupdate key \"value\" days passphrase\n"
@ -670,7 +670,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
//printf("flags.%d (%s) n.%d\n",flags,params[2].get_str().c_str(),n);
} else flags = 0;
if ( n >= 4 )
privkey = komodo_kvprivkey(&pubkey,(char *)(n >= 4 ? params[3].get_str().c_str() : "password"));
privkey = hush_kvprivkey(&pubkey,(char *)(n >= 4 ? params[3].get_str().c_str() : "password"));
haveprivkey = 1;
flags |= 1;
/*for (i=0; i<32; i++)
@ -690,7 +690,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
valuesize = (int32_t)strlen(params[1].get_str().c_str());
}
memcpy(keyvalue,key,keylen);
if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->GetHeight(),&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 )
if ( (refvaluesize= hush_kvsearch(&refpubkey,chainActive.LastTip()->GetHeight(),&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 )
{
if ( (tmpflags & HUSH_KVPROTECTED) != 0 )
{
@ -702,8 +702,8 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
}
if ( keylen+refvaluesize <= sizeof(keyvalue) )
{
sig = komodo_kvsig(keyvalue,keylen+refvaluesize,privkey);
if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 )
sig = hush_kvsig(keyvalue,keylen+refvaluesize,privkey);
if ( hush_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 )
{
ret.push_back(Pair("error",(char *)"error verifying sig, passphrase is probably wrong"));
printf("VERIFY ERROR\n");
@ -719,7 +719,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 )
ret.push_back(Pair("owner",refpubkey.GetHex()));
ret.push_back(Pair("height", (int64_t)height));
duration = komodo_kvduration(flags); //((flags >> 2) + 1) * HUSH_KVDURATION;
duration = hush_kvduration(flags); //((flags >> 2) + 1) * HUSH_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()));
@ -755,7 +755,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp, const CPubKey& mypk)
// 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();
fee = komodo_kvfee(flags,opretlen,keylen);
fee = hush_kvfee(flags,opretlen,keylen);
ret.push_back(Pair("fee",(double)fee/COIN));
CBitcoinAddress destaddress(CRYPTO555_HUSHADDR);
if (!destaddress.IsValid())

2
src/wallet/test/wallet_tests.cpp

@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0));
BOOST_CHECK_EQUAL(nValueRet, 1 * CENT); // we should get the exact amount
// run the 'mtgox' test (see http://blockexplorer.com/tx/29a3efd3ef04f9153d47a990bd7b048a4b2d213daaa5fb8ed670fb85f13bdbcf)
// run the 'mtgox' test
// they tried to consolidate 10 50k coins into one 500k coin, and ended up with 50k in change
empty_wallet();
for (int i = 0; i < 20; i++)

2
src/wallet/wallet.cpp

@ -2738,7 +2738,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
// Build initial witness caches for blocks involving one of our addresses
if (involvesMe) {
LogPrintf("%s: block has one of our transactions, building witness cache", __func__);
LogPrintf("%s: block has one of our transactions, building witness cache\n", __func__);
BuildWitnessCache(pindex, true);
}

Loading…
Cancel
Save