Merge branch 'FSM' of https://github.com/jl777/komodo into dev-komodo

This commit is contained in:
miketout
2018-11-21 23:34:30 -08:00
9 changed files with 48 additions and 23 deletions

View File

@@ -349,7 +349,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos));
threshold = total/maxinputs; threshold = total/(maxinputs+1);
if ( maxinputs > maxutxos ) if ( maxinputs > maxutxos )
maxutxos = maxinputs; maxutxos = maxinputs;
sum = 0; sum = 0;

View File

@@ -1464,7 +1464,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet
std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout)
{ {
CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; CMutableTransaction mtx,savemtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits;
entropyused = zeroid; entropyused = zeroid;
*resultp = 0; *resultp = 0;
funcid = 0; funcid = 0;
@@ -1579,6 +1579,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv
} }
CCchange = betTx.vout[0].nValue + betTx.vout[1].nValue; CCchange = betTx.vout[0].nValue + betTx.vout[1].nValue;
fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue;
savemtx = mtx;
if ( CCchange >= fundsneeded ) if ( CCchange >= fundsneeded )
CCchange -= fundsneeded; CCchange -= fundsneeded;
else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,1,sbits,fundingtxid)) >= fundsneeded ) else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,1,sbits,fundingtxid)) >= fundsneeded )
@@ -1588,6 +1589,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv
} }
else else
{ {
mtx = savemtx;
if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 )
{ {
if ( inputs > fundsneeded ) if ( inputs > fundsneeded )

View File

@@ -146,7 +146,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
GetCCaddress(cp,coinaddr,pk); GetCCaddress(cp,coinaddr,pk);
SetCCunspents(unspentOutputs,coinaddr); SetCCunspents(unspentOutputs,coinaddr);
threshold = total/maxinputs; threshold = total/(maxinputs+1);
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
{ {
txid = it->first.txhash; txid = it->first.txhash;

View File

@@ -336,7 +336,7 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
GetCCaddress(cp,coinaddr,pk); GetCCaddress(cp,coinaddr,pk);
SetCCunspents(unspentOutputs,coinaddr); SetCCunspents(unspentOutputs,coinaddr);
threshold = total/maxinputs; threshold = total/(maxinputs+1);
fprintf(stderr,"check %s for gateway inputs\n",coinaddr); fprintf(stderr,"check %s for gateway inputs\n",coinaddr);
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
{ {
@@ -576,7 +576,8 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t
mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,gatewayspk)); mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,gatewayspk));
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysBindOpRet('B',coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2))); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysBindOpRet('B',coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2)));
} }
fprintf(stderr,"cant find enough inputs\n"); CCerror = strprintf("cant find enough inputs");
fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
@@ -797,7 +798,8 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey())));
} }
} }
fprintf(stderr,"cant find enough inputs or mismatched total\n"); CCerror = strprintf("cant find enough inputs or mismatched total");
fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
@@ -836,7 +838,8 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret));
} }
} }
fprintf(stderr,"cant find enough inputs or mismatched total\n"); CCerror = strprintf("cant find enough inputs or mismatched total");
fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }

View File

@@ -794,12 +794,14 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector <uint8_t> da
mypk = pubkey2pk(Mypubkey()); mypk = pubkey2pk(Mypubkey());
if ( data.size() > 8192 ) if ( data.size() > 8192 )
{ {
fprintf(stderr,"datasize %d is too big\n",(int32_t)data.size()); CCerror = strprintf("datasize %d is too big",(int32_t)data.size());
fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( (datafee= OracleDatafee(pubKey,oracletxid,mypk)) <= 0 ) if ( (datafee= OracleDatafee(pubKey,oracletxid,mypk)) <= 0 )
{ {
fprintf(stderr,"datafee %.8f is illegal\n",(double)datafee/COIN); CCerror = strprintf("datafee %.8f is illegal",(double)datafee/COIN);
fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( txfee == 0 ) if ( txfee == 0 )
@@ -820,8 +822,14 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector <uint8_t> da
mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,batonpk)); mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,batonpk));
mtx.vout.push_back(CTxOut(datafee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(datafee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesData('D',oracletxid,batontxid,mypk,data))); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesData('D',oracletxid,batontxid,mypk,data)));
} else fprintf(stderr,"couldnt find enough oracle inputs %s, limit 1 per utxo\n",coinaddr); } else {
} else fprintf(stderr,"couldnt add normal inputs\n"); CCerror = strprintf("couldnt find enough oracle inputs %s, limit 1 per utxo\n",coinaddr);
fprintf(stderr,"%s\n", CCerror.c_str() );
}
} else {
CCerror = strprintf("couldnt add normal inputs\n");
fprintf(stderr,"%s\n", CCerror.c_str() );
}
return(""); return("");
} }

View File

@@ -333,7 +333,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
GetCCaddress(cp,coinaddr,pk); GetCCaddress(cp,coinaddr,pk);
SetCCunspents(unspentOutputs,coinaddr); SetCCunspents(unspentOutputs,coinaddr);
threshold = total/maxinputs; threshold = total/(maxinputs+1);
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
{ {
txid = it->first.txhash; txid = it->first.txhash;

View File

@@ -24,7 +24,7 @@ static const unsigned int MAX_BLOCK_SIZE = 2000000;
extern unsigned int MAX_BLOCK_SIGOPS; extern unsigned int MAX_BLOCK_SIGOPS;
/** The maximum size of a transaction (network rule) */ /** The maximum size of a transaction (network rule) */
static const unsigned int MAX_TX_SIZE_BEFORE_SAPLING = 100000; static const unsigned int MAX_TX_SIZE_BEFORE_SAPLING = 100000;
static const unsigned int MAX_TX_SIZE_AFTER_SAPLING = MAX_BLOCK_SIZE; static const unsigned int MAX_TX_SIZE_AFTER_SAPLING = (2 * MAX_TX_SIZE_BEFORE_SAPLING); //MAX_BLOCK_SIZE;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */ /** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
extern int COINBASE_MATURITY; extern int COINBASE_MATURITY;
/** The minimum value which is invalid for expiry height, used by CTransaction and CMutableTransaction */ /** The minimum value which is invalid for expiry height, used by CTransaction and CMutableTransaction */

View File

@@ -6,11 +6,11 @@
#define ZCASH_DEPRECATION_H #define ZCASH_DEPRECATION_H
// Deprecation policy: // Deprecation policy:
// * Shut down 16 weeks' worth of blocks after the estimated release block height. // * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height.
// * A warning is shown during the 2 weeks' worth of blocks prior to shut down. // * A warning is shown during the DEPRECATION_WARN_LIMIT worth of blocks prior to shut down.
static const int APPROX_RELEASE_HEIGHT = 1102000; static const int WEEKS_UNTIL_DEPRECATION = 52;
static const int WEEKS_UNTIL_DEPRECATION = 24; static const int DEPRECATION_HEIGHT = 1600000;
static const int DEPRECATION_HEIGHT = APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 60 * 24); static const int APPROX_RELEASE_HEIGHT = DEPRECATION_HEIGHT - (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60);
// Number of blocks before deprecation to warn users // Number of blocks before deprecation to warn users
static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months
@@ -18,10 +18,7 @@ static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months
/** /**
* Checks whether the node is deprecated based on the current block height, and * Checks whether the node is deprecated based on the current block height, and
* shuts down the node with an error if so (and deprecation is not disabled for * shuts down the node with an error if so (and deprecation is not disabled for
* the current client version). Warning and error messages are sent to the debug * the current client version).
* log, the metrics UI, and (if configured) -alertnofity.
*
* fThread means run -alertnotify in a free-running thread.
*/ */
void EnforceNodeDeprecation(int nHeight, bool forceLogging=false, bool fThread=true); void EnforceNodeDeprecation(int nHeight, bool forceLogging=false, bool fThread=true);

View File

@@ -5975,6 +5975,7 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp)
pubkeys.push_back(pubkey2pk(pubkey)); pubkeys.push_back(pubkey2pk(pubkey));
} }
hex = GatewaysBind(0,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys); hex = GatewaysBind(0,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6004,6 +6005,8 @@ UniValue gatewaysdeposit(const UniValue& params, bool fHelp)
if ( amount <= 0 || claimvout < 0 ) if ( amount <= 0 || claimvout < 0 )
throw runtime_error("invalid param: amount, numpks or claimvout\n"); throw runtime_error("invalid param: amount, numpks or claimvout\n");
hex = GatewaysDeposit(0,bindtxid,height,coin,cointxid,claimvout,deposithex,proof,pubkey2pk(destpub),amount); hex = GatewaysDeposit(0,bindtxid,height,coin,cointxid,claimvout,deposithex,proof,pubkey2pk(destpub),amount);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6027,6 +6030,7 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp)
destpub = ParseHex(params[3].get_str()); destpub = ParseHex(params[3].get_str());
amount = atof((char *)params[4].get_str().c_str()) * COIN + 0.00000000499999; amount = atof((char *)params[4].get_str().c_str()) * COIN + 0.00000000499999;
hex = GatewaysClaim(0,bindtxid,coin,deposittxid,pubkey2pk(destpub),amount); hex = GatewaysClaim(0,bindtxid,coin,deposittxid,pubkey2pk(destpub),amount);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6049,6 +6053,7 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp)
withdrawpub = ParseHex(params[2].get_str()); withdrawpub = ParseHex(params[2].get_str());
amount = atof((char *)params[3].get_str().c_str()) * COIN + 0.00000000499999; amount = atof((char *)params[3].get_str().c_str()) * COIN + 0.00000000499999;
hex = GatewaysWithdraw(0,bindtxid,coin,pubkey2pk(withdrawpub),amount); hex = GatewaysWithdraw(0,bindtxid,coin,pubkey2pk(withdrawpub),amount);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6070,6 +6075,7 @@ UniValue gatewaysmarkdone(const UniValue& params, bool fHelp)
coin = params[1].get_str(); coin = params[1].get_str();
cointxid = Parseuint256((char *)params[2].get_str().c_str()); cointxid = Parseuint256((char *)params[2].get_str().c_str());
hex = GatewaysMarkdone(0,withdrawtxid,coin,cointxid); hex = GatewaysMarkdone(0,withdrawtxid,coin,cointxid);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6116,6 +6122,7 @@ UniValue gatewayspartialsign(const UniValue& params, bool fHelp)
coin = params[1].get_str(); coin = params[1].get_str();
parthex = params[2].get_str(); parthex = params[2].get_str();
hex = GatewaysPartialSign(0,txid,coin,parthex); hex = GatewaysPartialSign(0,txid,coin,parthex);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6157,6 +6164,7 @@ UniValue oraclesregister(const UniValue& params, bool fHelp)
if ( (datafee= atol((char *)params[1].get_str().c_str())) == 0 ) if ( (datafee= atol((char *)params[1].get_str().c_str())) == 0 )
datafee = atof((char *)params[1].get_str().c_str()) * COIN + 0.00000000499999; datafee = atof((char *)params[1].get_str().c_str()) * COIN + 0.00000000499999;
hex = OracleRegister(0,txid,datafee); hex = OracleRegister(0,txid,datafee);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6178,6 +6186,7 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp)
pubkey = ParseHex(params[1].get_str().c_str()); pubkey = ParseHex(params[1].get_str().c_str());
amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999; amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999;
hex = OracleSubscribe(0,txid,pubkey2pk(pubkey),amount); hex = OracleSubscribe(0,txid,pubkey2pk(pubkey),amount);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6211,6 +6220,9 @@ UniValue oraclesdata(const UniValue& params, bool fHelp)
txid = Parseuint256((char *)params[0].get_str().c_str()); txid = Parseuint256((char *)params[0].get_str().c_str());
data = ParseHex(params[1].get_str().c_str()); data = ParseHex(params[1].get_str().c_str());
hex = OracleData(0,txid,data); hex = OracleData(0,txid,data);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6265,6 +6277,7 @@ UniValue oraclescreate(const UniValue& params, bool fHelp)
return(result); return(result);
} }
hex = OracleCreate(0,name,description,format); hex = OracleCreate(0,name,description,format);
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -6668,8 +6681,10 @@ UniValue dicestatus(const UniValue& params, bool fHelp)
{ {
if ( params.size() == 3 ) if ( params.size() == 3 )
{ {
int64_t val;
val = winnings * COIN + 0.00000000499999;
result.push_back(Pair("status", "win")); result.push_back(Pair("status", "win"));
result.push_back(Pair("won", winnings)); result.push_back(Pair("won", ValueFromAmount(val)));
} }
else else
{ {