Merge pull request #173 from jl777/dev

Dev
This commit is contained in:
jl777
2017-02-07 06:20:30 +02:00
committed by GitHub
6 changed files with 46 additions and 15 deletions

View File

@@ -335,6 +335,11 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
return(-1); return(-1);
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
{ {
if ( i == 0 && j == 0 && memcmp(NOTARY_PUBKEY33,scriptbuf+1,33) == 0 )
{
printf("KOMODO_LASTMINED.%d -> %d\n",KOMODO_LASTMINED,height);
KOMODO_LASTMINED = height;
}
decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR);
/*for (k=0; k<33; k++) /*for (k=0; k<33; k++)
printf("%02x",crypto777[k]); printf("%02x",crypto777[k]);

View File

@@ -704,7 +704,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
bitcoin_address(coinaddr,addrtype,rmd160,20); bitcoin_address(coinaddr,addrtype,rmd160,20);
checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis);
typestr = "deposit"; typestr = "deposit";
if ( kmdheight <= height ) if ( kmdheight > 195000 || kmdheight <= height )
{ {
didstats = 0; didstats = 0;
if ( 0 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 ) if ( 0 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
@@ -769,7 +769,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
} }
else if ( seed != 0 && kmdheight > 182000 && strcmp(base,ASSETCHAINS_SYMBOL) == 0 ) else if ( seed != 0 && kmdheight > 182000 && strcmp(base,ASSETCHAINS_SYMBOL) == 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); 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); } //else printf("paxdeposit height.%d vs kmdheight.%d\n",height,kmdheight);
} }
} }
else if ( opretbuf[0] == 'I' ) else if ( opretbuf[0] == 'I' )

View File

@@ -40,6 +40,7 @@ struct komodo_state KOMODO_STATES[34];
int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
int32_t IS_KOMODO_NOTARY,KOMODO_REWIND,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET; int32_t IS_KOMODO_NOTARY,KOMODO_REWIND,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET;
int32_t KOMODO_LASTMINED;
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES;
uint8_t NOTARY_PUBKEY33[33]; uint8_t NOTARY_PUBKEY33[33];

View File

@@ -522,6 +522,7 @@ static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& rese
int32_t komodo_baseid(char *origbase); int32_t komodo_baseid(char *origbase);
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height); int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height);
int32_t FOUND_BLOCK; int32_t FOUND_BLOCK;
extern int32_t KOMODO_LASTMINED;
void static BitcoinMiner(CWallet *pwallet) void static BitcoinMiner(CWallet *pwallet)
{ {
@@ -641,7 +642,7 @@ void static BitcoinMiner(CWallet *pwallet)
if ( externalflag == 0 && i != 66 ) if ( externalflag == 0 && i != 66 )
printf("VIOLATION at %d\n",i); printf("VIOLATION at %d\n",i);
for (i=0; i<66; i++) for (i=0; i<66; i++)
{ {break;
for (j=0; j<33; j++) for (j=0; j<33; j++)
printf("%02x",pubkeys[i][j]); printf("%02x",pubkeys[i][j]);
printf(" p%d -> %d\n",i,komodo_minerid(pindexPrev->nHeight-i,pubkeys[i])); printf(" p%d -> %d\n",i,komodo_minerid(pindexPrev->nHeight-i,pubkeys[i]));
@@ -658,7 +659,7 @@ void static BitcoinMiner(CWallet *pwallet)
if ( mids[j] == notaryid ) if ( mids[j] == notaryid )
break; break;
} else fprintf(stderr,"no nonz pubkeys\n"); } else fprintf(stderr,"no nonz pubkeys\n");
if ( j == 65 ) if ( j == 65 && Mining_height > KOMODO_LASTMINED+64 )
{ {
hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS);
fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1); fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1);
@@ -799,7 +800,7 @@ void static BitcoinMiner(CWallet *pwallet)
{ {
FOUND_BLOCK = 0; FOUND_BLOCK = 0;
fprintf(stderr,"FOUND_BLOCK!\n"); fprintf(stderr,"FOUND_BLOCK!\n");
sleep(2000); //sleep(2000);
} }
if (vNodes.empty() && chainparams.MiningRequiresPeers()) if (vNodes.empty() && chainparams.MiningRequiresPeers())
{ {

View File

@@ -45,6 +45,7 @@ uint64_t komodo_interestsum();
int32_t komodo_longestchain(); int32_t komodo_longestchain();
int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp);
int32_t komodo_whoami(char *pubkeystr,int32_t height); int32_t komodo_whoami(char *pubkeystr,int32_t height);
extern int32_t KOMODO_LASTMINED;
Value getinfo(const Array& params, bool fHelp) Value getinfo(const Array& params, bool fHelp)
{ {
@@ -128,6 +129,8 @@ Value getinfo(const Array& params, bool fHelp)
notaryid = komodo_whoami(pubkeystr,longestchain); notaryid = komodo_whoami(pubkeystr,longestchain);
obj.push_back(Pair("notaryid", notaryid)); obj.push_back(Pair("notaryid", notaryid));
obj.push_back(Pair("pubkey", pubkeystr)); obj.push_back(Pair("pubkey", pubkeystr));
if ( KOMODO_LASTMINED != 0 )
obj.push_back(Pair("lastmined", KOMODO_LASTMINED));
} }
return obj; return obj;
} }

View File

@@ -2342,7 +2342,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
setCoinsRet.clear(); setCoinsRet.clear();
memset(interests,0,sizeof(interests)); memset(interests,0,sizeof(interests));
nValueRet = 0; nValueRet = 0;
*interestp = 0; //*interestp = 0;
// List of values less than target // List of values less than target
pair<CAmount, pair<const CWalletTx*,unsigned int> > coinLowestLarger; pair<CAmount, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
coinLowestLarger.first = std::numeric_limits<CAmount>::max(); coinLowestLarger.first = std::numeric_limits<CAmount>::max();
@@ -2458,10 +2458,12 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl,uint64_t *interestp) const bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl,uint64_t *interestp) const
{ {
// Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos. // Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos.
uint64_t tmp; uint64_t tmp,interest = 0;
if ( interestp == 0 ) if ( interestp == 0 )
{
interestp = &tmp; interestp = &tmp;
*interestp = 0; *interestp = 0;
}
vector<COutput> vCoinsNoCoinbase, vCoinsWithCoinbase; vector<COutput> vCoinsNoCoinbase, vCoinsWithCoinbase;
AvailableCoins(vCoinsNoCoinbase, true, coinControl, false, false); AvailableCoins(vCoinsNoCoinbase, true, coinControl, false, false);
AvailableCoins(vCoinsWithCoinbase, true, coinControl, false, true); AvailableCoins(vCoinsWithCoinbase, true, coinControl, false, true);
@@ -2510,9 +2512,25 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*
return (nValueRet >= nTargetValue); return (nValueRet >= nTargetValue);
} }
//fprintf(stderr,"nValueRet %8f vs target %.8f\n",(double)nValueRet/COIN,(double)nTargetValue/COIN); //fprintf(stderr,"nValueRet %8f vs target %.8f\n",(double)nValueRet/COIN,(double)nTargetValue/COIN);
return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,interestp) || if ( SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,&interest) != 0 )
SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,interestp) || {
(bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,interestp))); *interestp += interest;
return(true);
}
else if ( SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,&interest) != 0 )
{
*interestp += interest;
return(true);
}
else if ( bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,&interest) != 0 )
{
*interestp += interest;
return(true);
}
return(false);
//return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,interestp) ||
// SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,interestp) ||
// (bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,interestp)));
} }
bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
@@ -2569,13 +2587,13 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
{ {
txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now
} }
{ {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
{ {
nFeeRet = 0; nFeeRet = 0;
while (true) while (true)
{ {
interest = 0;
txNew.vin.clear(); txNew.vin.clear();
txNew.vout.clear(); txNew.vout.clear();
wtxNew.fFromMe = true; wtxNew.fFromMe = true;
@@ -2623,7 +2641,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
CAmount nValueIn = 0; CAmount nValueIn = 0;
bool fOnlyCoinbaseCoins = false; bool fOnlyCoinbaseCoins = false;
bool fNeedCoinbaseCoins = false; bool fNeedCoinbaseCoins = false;
interest = interest2 = 0; interest2 = 0;
if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl,&interest)) if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl,&interest))
{ {
if (fOnlyCoinbaseCoins && Params().GetConsensus().fCoinbaseMustBeProtected) { if (fOnlyCoinbaseCoins && Params().GetConsensus().fCoinbaseMustBeProtected) {
@@ -2644,7 +2662,10 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
//But mempool inputs might still be in the mempool, so their age stays 0 //But mempool inputs might still be in the mempool, so their age stays 0
//fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); //fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN);
if ( KOMODO_EXCHANGEWALLET == 0 ) if ( KOMODO_EXCHANGEWALLET == 0 )
{
interest2 += pcoin.first->vout[pcoin.second].interest; interest2 += pcoin.first->vout[pcoin.second].interest;
fprintf(stderr,"%.8f ",(double)pcoin.first->vout[pcoin.second].interest/COIN);
}
int age = pcoin.first->GetDepthInMainChain(); int age = pcoin.first->GetDepthInMainChain();
if (age != 0) if (age != 0)
age += 1; age += 1;
@@ -2655,8 +2676,8 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
//fprintf(stderr,"KOMODO_EXCHANGEWALLET disable interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); //fprintf(stderr,"KOMODO_EXCHANGEWALLET disable interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN);
interest = 0; interest = 0;
} }
CAmount nChange = (nValueIn - nValue + interest); CAmount nChange = (nValueIn - nValue + interest2);
fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN,(double)nTotalValue/COIN); fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)interest/COIN,(double)nTotalValue/COIN);
if (nSubtractFeeFromAmount == 0) if (nSubtractFeeFromAmount == 0)
nChange -= nFeeRet; nChange -= nFeeRet;