Merge branch 'jl777' into FSM

# Conflicts:
#	src/cc/rewards.cpp
#	src/main.cpp
This commit is contained in:
jl777
2018-08-31 22:07:10 -11:00
12 changed files with 327 additions and 32 deletions

View File

@@ -55,6 +55,9 @@ std::string CCerror;
// Private method:
UniValue z_getoperationstatus_IMPL(const UniValue&, bool);
#define PLAN_NAME_MAX 8
#define VALID_PLAN_NAME(x) (strlen(x) <= PLAN_NAME_MAX)
std::string HelpRequiringPassphrase()
{
return pwalletMain && pwalletMain->IsCrypted()
@@ -5467,6 +5470,12 @@ UniValue dicefund(const UniValue& params, bool fHelp)
maxbet = atof(params[3].get_str().c_str()) * COIN;
maxodds = atol(params[4].get_str().c_str());
timeoutblocks = atol(params[5].get_str().c_str());
if (!VALID_PLAN_NAME(name)) {
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
return(result);
}
hex = DiceCreateFunding(0,name,funds,minbet,maxbet,maxodds,timeoutblocks);
if (CCerror != "") {
ERR_RESULT(CCerror);
@@ -5491,6 +5500,10 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp)
name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN;
if (!VALID_PLAN_NAME(name)) {
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
return(result);
}
if ( amount > 0 ) {
hex = DiceAddfunding(0,name,fundingtxid,amount);
if (CCerror != "") {
@@ -5516,6 +5529,11 @@ UniValue dicebet(const UniValue& params, bool fHelp)
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN;
odds = atol(params[3].get_str().c_str());
if (!VALID_PLAN_NAME(name)) {
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
return(result);
}
if (amount > 0 && odds > 0) {
hex = DiceBet(0,name,fundingtxid,amount,odds);
if ( hex.size() > 0 )
@@ -5539,6 +5557,10 @@ UniValue dicefinish(const UniValue& params, bool fHelp)
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str();
if (!VALID_PLAN_NAME(name)) {
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
return(result);
}
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
bettxid = Parseuint256((char *)params[2].get_str().c_str());
hex = DiceBetFinish(&r,0,name,fundingtxid,bettxid,1);
@@ -5563,6 +5585,10 @@ UniValue dicestatus(const UniValue& params, bool fHelp)
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str();
if (!VALID_PLAN_NAME(name)) {
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
return(result);
}
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
memset(&bettxid,0,sizeof(bettxid));
if ( params.size() == 3 )
@@ -5686,9 +5712,14 @@ UniValue tokencreate(const UniValue& params, bool fHelp)
LOCK2(cs_main, pwalletMain->cs_wallet);
name = params[0].get_str();
supply = atof(params[1].get_str().c_str()) * COIN;
if ( name.size() == 0 || supply <= 0 )
if ( name.size() == 0 || name.size() > 32)
{
result.push_back(Pair("error", "invalid parameter"));
ERR_RESULT("Token name must not be empty and up to 32 characters");
return(result);
}
if ( supply <= 0 )
{
ERR_RESULT("Token supply must be positive");
return(result);
}
if ( params.size() == 3 )
@@ -5696,7 +5727,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp)
description = params[2].get_str();
if ( description.size() > 4096 )
{
result.push_back(Pair("error", "token description longer than 4096"));
ERR_RESULT("Token description must be <= 4096 characters");
return(result);
}
}
@@ -5721,9 +5752,14 @@ UniValue tokentransfer(const UniValue& params, bool fHelp)
tokenid = Parseuint256((char *)params[0].get_str().c_str());
std::vector<unsigned char> pubkey(ParseHex(params[1].get_str().c_str()));
amount = atol(params[2].get_str().c_str());
if ( tokenid == zeroid || amount <= 0 )
if ( tokenid == zeroid )
{
result.push_back(Pair("error", "invalid parameter"));
ERR_RESULT("invalid tokenid");
return(result);
}
if ( amount <= 0 )
{
ERR_RESULT("amount must be positive");
return(result);
}
hex = AssetTransfer(0,tokenid,pubkey,amount);
@@ -5752,9 +5788,19 @@ UniValue tokenbid(const UniValue& params, bool fHelp)
tokenid = Parseuint256((char *)params[1].get_str().c_str());
price = atof(params[2].get_str().c_str());
bidamount = (price * numtokens) * COIN + 0.0000000049999;
if ( tokenid == zeroid || tokenid == zeroid || price <= 0 || bidamount <= 0 )
if ( price <= 0 )
{
result.push_back(Pair("error", "invalid parameter"));
ERR_RESULT("price must be positive");
return(result);
}
if ( tokenid == zeroid )
{
ERR_RESULT("invalid tokenid");
return(result);
}
if ( bidamount <= 0 )
{
ERR_RESULT("bid amount must be positive");
return(result);
}
hex = CreateBuyOffer(0,bidamount,tokenid,numtokens);
@@ -5763,7 +5809,7 @@ UniValue tokenbid(const UniValue& params, bool fHelp)
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else result.push_back(Pair("error", "couldnt create bid"));
} else ERR_RESULT("couldnt create bid");
} else {
ERR_RESULT("price and numtokens must be positive");
}