diff --git a/src/komodo.h b/src/komodo.h index 94fb1347c..bdb692d09 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -446,7 +446,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr printf("ISRATIFICATION (%s)\n",(char *)&scriptbuf[len+32*2+4]); } } - if ( *isratificationp == 0 ) + if ( *isratificationp == 0 && (signedmask != 0 || (scriptbuf[len] != 'X' && scriptbuf[len] != 'A' && scriptbuf[len] != 'I')) ) komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j); } } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cf7d01201..0441ce22c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -17,7 +17,7 @@ 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 baseid; struct komodo_state *sp; int64_t netliability,maxallowed; + int32_t baseid; struct komodo_state *sp; int64_t netliability,maxallowed,maxval; *available = *deposited = *issued = *withdrawn = *approved = *redeemed = 0; if ( (baseid= komodo_baseid(base)) >= 0 ) { @@ -28,7 +28,10 @@ int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued, *withdrawn = sp->withdrawn; *approved = sp->approved; *redeemed = sp->redeemed; - netliability = (sp->deposited - sp->withdrawn) - sp->shorted; + maxval = sp->approved; + if ( sp->withdrawn > maxval ) + maxval = sp->withdrawn; + netliability = (sp->issued - maxval) - sp->shorted; maxallowed = komodo_maxallowed(baseid); if ( netliability < maxallowed ) *available = (maxallowed - netliability); @@ -528,6 +531,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to { if ( strcmp(pax->symbol,ASSETCHAINS_SYMBOL) == 0 ) printf("pax->symbol.%s != %s or null pax->validated %.8f ready.%d ht.(%d %d)\n",pax->symbol,symbol,dstr(pax->validated),pax->ready,kmdsp->CURRENT_HEIGHT,pax->height); + pax->marked = pax->fiatoshis; continue; } if ( pax->ready == 0 ) @@ -571,7 +575,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to PENDING_KOMODO_TX += pax->komodoshis; printf(" len.%d vout.%u DEPOSIT %.8f <- pax.%s pending ht %d %d %.8f | ",len,pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,pax->height,pax->otherheight,dstr(PENDING_KOMODO_TX)); } - if ( numvouts++ >= 64 ) + if ( numvouts++ >= 1 ) break; } if ( numvouts > 1 ) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 7779eba6e..2aa745070 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -73,6 +73,8 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin { if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) { + if ( minutes > 365 * 24 * 60 ) + minutes = 365 * 24 * 60; denominator = (((uint64_t)365 * 24 * 60) / minutes); if ( denominator == 0 ) denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually! @@ -102,7 +104,9 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin if ( exception == 0 ) { numerator = (nValue / 20); // assumes 5%! - interest = (numerator / denominator); + if ( txheight < 300000 ) + interest = (numerator / denominator); + else interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60); } else { @@ -113,7 +117,9 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin else { numerator = (nValue * KOMODO_INTEREST); - interest = (numerator / denominator) / COIN; + if ( txheight < 300000 || numerator * minutes < 365 * 24 * 60 ) + interest = (numerator / denominator) / COIN; + else interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)) / COIN; } //fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator); } diff --git a/src/miner.cpp b/src/miner.cpp index e9ab80741..40226176d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -101,7 +101,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #define ASSETCHAINS_MINHEIGHT 100 #define KOMODO_ELECTION_GAP 2000 #define ROUNDROBIN_DELAY 59 -extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE; +extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern char ASSETCHAINS_SYMBOL[16]; extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[33]; @@ -133,7 +133,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) while ( KOMODO_ON_DEMAND == 0 && deposits == 0 && (int32_t)mempool.GetTotalTxSize() == 0 ) { deposits = komodo_paxtotal(); - if ( KOMODO_INITDONE == 0 || (komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 && (isrealtime= komodo_isrealtime(&kmdheight)) == 0) ) + if ( KOMODO_PASSPORT_INITDONE == 0 || KOMODO_INITDONE == 0 || (komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 && (isrealtime= komodo_isrealtime(&kmdheight)) == 0) ) { //fprintf(stderr,"INITDONE.%d RT.%d deposits %.8f ht.%d\n",KOMODO_INITDONE,isrealtime,(double)deposits/COIN,kmdheight); } @@ -629,6 +629,15 @@ void static BitcoinMiner(CWallet *pwallet) return; } CBlock *pblock = &pblocktemplate->block; + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + if ( pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) + { + fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL); + sleep(10); + continue; + } else fprintf(stderr,"vouts.%d mining.%d vs %d\n",(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT); + } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); LogPrintf("Running KomodoMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // @@ -685,12 +694,12 @@ void static BitcoinMiner(CWallet *pwallet) } else Mining_start = 0; while (true) { - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) // skips when it shouldnt + /*if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) // skips when it shouldnt { fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL); sleep(10); break; - } + }*/ // Hash state KOMODO_CHOSEN_ONE = 0; crypto_generichash_blake2b_state state; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e68ccc9be..53a2bfd03 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -496,6 +496,8 @@ 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); +uint64_t komodo_maxallowed(int32_t baseid); +int32_t komodo_baseid(char *origbase); Value kvupdate(const Array& params, bool fHelp) { @@ -627,11 +629,24 @@ Value paxdeposit(const Array& params, bool fHelp) CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); - int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; + int32_t baseid,errflag = 0; int64_t netliability,minval,maxallowed,fiatoshis = atof(params[1].get_str().c_str()) * COIN; std::string base = params[2].get_str(); std::string dest; height = chainActive.Tip()->nHeight; + baseid = komodo_baseid((char *)base.c_str()); if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis ) + errflag = 1; + else + { + minval = approved; + if ( withdrawn < minval ) + minval = withdrawn; + netliability = (deposited - minval); + maxallowed = komodo_maxallowed(baseid); + if ( fiatoshis > (maxallowed - netliability) ) + errflag = 1; + } + if ( errflag != 0 ) throw runtime_error("paxdeposit not enough available inventory"); komodoshis = PAX_fiatdest(&seed,0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),height,(char *)base.c_str(),fiatoshis); dest.append(destaddr); @@ -659,6 +674,7 @@ Value paxwithdraw(const Array& params, bool fHelp) return(0); if (!EnsureWalletIsAvailable(fHelp)) return 0; + throw runtime_error("paxwithdraw deprecated"); if (fHelp || params.size() != 2) throw runtime_error("paxwithdraw address fiatamount"); if ( komodo_isrealtime(&kmdheight) == 0 )