Skip to content

Commit

Permalink
Merge pull request #302 from jl777/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
jl777 authored Mar 17, 2017
2 parents d9fb650 + f9f1ce1 commit 462cac0
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/assetchains
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash
set -x
source pubkey.txt
echo $pubkey
Expand Down
3 changes: 2 additions & 1 deletion src/komodo.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ 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);
}
}
Expand Down
54 changes: 40 additions & 14 deletions src/komodo_gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -28,11 +28,14 @@ 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);
//printf("%p %s %.8f %.8f %.8f %.8f %.8f\n",sp,base,dstr(*deposited),dstr(*issued),dstr(*withdrawn),dstr(*approved),dstr(*redeemed));
//printf("%llu - %llu %s %.8f %.8f %.8f %.8f %.8f\n",(long long)maxallowed,(long long)netliability,base,dstr(*deposited),dstr(*issued),dstr(*withdrawn),dstr(*approved),dstr(*redeemed));
return(0);
} else printf("pax_fiatstatus cant get basesp.%s\n",base);
} // else printf("pax_fiatstatus illegal base.%s\n",base);
Expand Down Expand Up @@ -265,7 +268,7 @@ int32_t komodo_paxcmp(char *symbol,int32_t kmdheight,uint64_t value,uint64_t che
if ( seed == 0 && checkvalue != 0 )
{
ratio = ((value << 6) / checkvalue);
if ( ratio >= 63 && ratio <= 65 )
if ( ratio >= 62 && ratio <= 66 )
return(0);
else
{
Expand Down Expand Up @@ -486,7 +489,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
else
{
opcode = 'X';
if ( komodo_paxtotal() == 0 )
if ( 1 || komodo_paxtotal() == 0 )
return(0);
}
HASH_ITER(hh,PAX,pax,tmp)
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -659,17 +663,32 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data();
if ( n <= 2 || script[0] != 0x6a )
{
int64_t val,prevtotal = 0; int32_t overflow = 0;
total = 0;
for (i=1; i<n; i++)
total += block.vtx[0].vout[i].nValue;
if ( total > COIN/10 )
{
if ( (val= block.vtx[0].vout[i].nValue) < 0 || val >= MAX_MONEY )
{
overflow = 1;
break;
}
total += val;
if ( total < prevtotal || (val != 0 && total == prevtotal) )
{
overflow = 1;
break;
}
prevtotal = total;
}
if ( overflow != 0 || total > COIN/10 )
{
//fprintf(stderr,">>>>>>>> <<<<<<<<<< ht.%d illegal nonz output %.8f n.%d\n",height,dstr(block.vtx[0].vout[1].nValue),n);
if ( height >= 235300 )
return(-1);
}
return(0);
}

//fprintf(stderr,"ht.%d n.%d nValue %.8f (%d %d %d)\n",height,n,dstr(block.vtx[0].vout[1].nValue),KOMODO_PAX,komodo_isrealtime(&ht),KOMODO_PASSPORT_INITDONE);
if ( komodo_isrealtime(&ht) == 0 || KOMODO_PASSPORT_INITDONE == 0 ) //KOMODO_PAX == 0 ||
return(0);
Expand All @@ -680,6 +699,8 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
// printf("%02x",script[i]);
//printf(" height.%d checkdeposit n.%d [%02x] [%c] %d vs %d\n",height,n,script[0],script[offset],script[offset],'X');
opcode = 'X';
if ( height >= 235300 )
return(-1);
strcpy(symbol,(char *)"KMD");
}
else
Expand Down Expand Up @@ -859,7 +880,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
if ( 0 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
printf("########### %p depositedB %s += %.8f/%.8f kmdheight.%d/%d %.8f/%.8f\n",basesp,base,dstr(fiatoshis),dstr(pax->fiatoshis),kmdheight,pax->height,dstr(value),dstr(pax->komodoshis));
}
}
} //
if ( didstats != 0 )
pax->didstats = 1;
if ( (pax2= komodo_paxfind(txid,vout,'I')) != 0 )
Expand All @@ -881,8 +902,13 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
}
}
}
else if ( kmdheight > 238000 && (kmdheight > 214700 || strcmp(base,ASSETCHAINS_SYMBOL) == 0) ) //seed != 0 &&
printf("pax %s deposit %.8f rejected kmdheight.%d %.8f KMD check %.8f seed.%llu\n",base,dstr(fiatoshis),kmdheight,dstr(value),dstr(checktoshis),(long long)seed);
else
{
if ( (pax= komodo_paxfind(txid,vout,'D')) != 0 )
pax->marked = checktoshis;
if ( kmdheight > 238000 && (kmdheight > 214700 || strcmp(base,ASSETCHAINS_SYMBOL) == 0) ) //seed != 0 &&
printf("pax %s deposit %.8f rejected kmdheight.%d %.8f KMD check %.8f seed.%llu\n",base,dstr(fiatoshis),kmdheight,dstr(value),dstr(checktoshis),(long long)seed);
}
} //else printf("paxdeposit height.%d vs kmdheight.%d\n",height,kmdheight);
}
}
Expand Down Expand Up @@ -935,7 +961,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
} //else printf("opreturn none issued?\n");
}
}
else if ( opretbuf[0] == 'W' )//&& opretlen >= 38 )
else if ( height < 236000 && opretbuf[0] == 'W' )//&& opretlen >= 38 )
{
if ( komodo_baseid((char *)&opretbuf[opretlen-4]) >= 0 && strcmp(ASSETCHAINS_SYMBOL,(char *)&opretbuf[opretlen-4]) == 0 )
{
Expand Down Expand Up @@ -980,7 +1006,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
} // else printf("withdraw %s paxcmp ht.%d %d error value %.8f -> %.8f vs %.8f\n",base,kmdheight,height,dstr(value),dstr(komodoshis),dstr(checktoshis));
// need to allocate pax
}
else if ( tokomodo != 0 && opretbuf[0] == 'A' )
else if ( height < 236000 && tokomodo != 0 && opretbuf[0] == 'A' )
{
tokomodo = 1;
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
Expand Down Expand Up @@ -1059,7 +1085,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
} //else printf("n.%d from opreturns\n",n);
//printf("extra.[%d] after %.8f\n",n,dstr(komodo_paxtotal()));
}
else if ( opretbuf[0] == 'X' )
else if ( height < 236000 && opretbuf[0] == 'X' )
{
tokomodo = 1;
if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 )
Expand Down
10 changes: 8 additions & 2 deletions src/komodo_interest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
{
Expand All @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3258,7 +3258,6 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
else if ( komodo_checkpoint(&notarized_height,nHeight,hash) < 0 )
return state.DoS(100, error("%s: forked chain %d older than last notarized (height %d) vs %d", __func__,nHeight, notarized_height));
}

// Reject block.nVersion < 4 blocks
if (block.nVersion < 4)
return state.Invalid(error("%s : rejected nVersion<4 block", __func__),
Expand Down
24 changes: 18 additions & 6 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -403,9 +403,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
else if ( komodo_is_issuer() != 0 )
{
komodo_gateway_deposits(&txNew,ASSETCHAINS_SYMBOL,0);
//if ( txNew.vout.size() > 1 )
if ( txNew.vout.size() > 1 )
fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size());
}

pblock->vtx[0] = txNew;
pblocktemplate->vTxFees[0] = -nFees;
// Randomise nonce
Expand Down Expand Up @@ -612,7 +613,7 @@ void static BitcoinMiner(CWallet *pwallet)
Mining_height = pindexPrev->nHeight+1;
Mining_start = (uint32_t)time(NULL);
}
if ( ASSETCHAINS_SYMBOL[0] != 0 )
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
fprintf(stderr,"%s create new block ht.%d\n",ASSETCHAINS_SYMBOL,Mining_height);
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey);
if ( ptr == 0 )
Expand All @@ -629,6 +630,17 @@ 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 )
{
static uint32_t counter;
if ( counter++ < 10 )
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));
//
Expand Down Expand Up @@ -685,12 +697,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;
Expand Down
4 changes: 4 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,10 @@ Value paxdeposit(const Array& params, bool fHelp)
std::string dest;
height = chainActive.Tip()->nHeight;
if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis )
{
fprintf(stderr,"available %llu vs fiatoshis %llu\n",(long long)available,(long long)fiatoshis);
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);
CBitcoinAddress destaddress(CRYPTO777_KMDADDR);
Expand All @@ -659,6 +662,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 )
Expand Down

0 comments on commit 462cac0

Please sign in to comment.