Test refactoring, more tests, and lots of error checking improvements and uint64_t fixes
This commit is contained in:
@@ -38,6 +38,9 @@
|
||||
|
||||
#include <numeric>
|
||||
|
||||
#define ERR_RESULT(x) result.push_back(Pair("result", "error")); \
|
||||
result.push_back(Pair("error", x));
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace libzcash;
|
||||
@@ -49,6 +52,8 @@ uint32_t komodo_segid32(char *coinaddr);
|
||||
|
||||
int64_t nWalletUnlockTime;
|
||||
static CCriticalSection cs_nWalletUnlockTime;
|
||||
//TODO: find a better place for this
|
||||
std::string CCerror;
|
||||
|
||||
// Private method:
|
||||
UniValue z_getoperationstatus_IMPL(const UniValue&, bool);
|
||||
@@ -5074,7 +5079,10 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp)
|
||||
txid = Parseuint256((char *)params[2].get_str().c_str());
|
||||
else memset(&txid,0,sizeof(txid));
|
||||
hex = RewardsUnlock(0,name,fundingtxid,txid);
|
||||
if ( hex.size() > 0 )
|
||||
if (CCerror != "") {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", CCerror));
|
||||
} else if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
@@ -5194,8 +5202,7 @@ UniValue faucetget(const UniValue& params, bool fHelp)
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
hex = FaucetGet(0);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
if ( hex.size() > 0 ) {
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else {
|
||||
@@ -5221,17 +5228,22 @@ UniValue dicefund(const UniValue& params, bool fHelp)
|
||||
maxodds = atol(params[4].get_str().c_str());
|
||||
timeoutblocks = atol(params[5].get_str().c_str());
|
||||
hex = DiceCreateFunding(0,name,funds,minbet,maxbet,maxodds,timeoutblocks);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
if (CCerror != "") {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", CCerror));
|
||||
} else if ( hex.size() > 0 ) {
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create dice funding transaction"));
|
||||
} else {
|
||||
result.push_back(Pair("error", "couldnt create dice funding transaction"));
|
||||
result.push_back(Pair("result", "error"));
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue diceaddfunds(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; uint64_t amount; std::string hex;
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; int64_t amount; std::string hex;
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("diceaddfunds name fundingtxid amount\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5241,18 +5253,28 @@ 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;
|
||||
hex = DiceAddfunding(0,name,fundingtxid,amount);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create dice addfunding transaction"));
|
||||
if ( amount > 0 ) {
|
||||
hex = DiceAddfunding(0,name,fundingtxid,amount);
|
||||
if (CCerror != "") {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", CCerror));
|
||||
} else if ( hex.size() > 0 ) {
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "couldnt create dice addfunding transaction"));
|
||||
}
|
||||
} else {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "amount must be positive"));
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue dicebet(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; uint64_t amount,odds; char *name;
|
||||
UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; int64_t amount,odds; char *name;
|
||||
if ( fHelp || params.size() != 4 )
|
||||
throw runtime_error("dicebet name fundingtxid amount odds\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5263,18 +5285,24 @@ 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());
|
||||
hex = DiceBet(0,name,fundingtxid,amount,odds);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create faucet get transaction"));
|
||||
if (amount > 0 && odds > 0) {
|
||||
hex = DiceBet(0,name,fundingtxid,amount,odds);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else {
|
||||
ERR_RESULT("couldnt create faucet get transaction");
|
||||
}
|
||||
} else {
|
||||
ERR_RESULT("amount and odds must be positive");
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue dicefinish(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; int32_t r;
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string hex; int32_t r;
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("dicefinish name fundingtxid bettxid\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5295,7 +5323,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue dicestatus(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string status; double winnings;
|
||||
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string status; double winnings;
|
||||
if ( fHelp || (params.size() != 2 && params.size() != 3) )
|
||||
throw runtime_error("dicestatus name fundingtxid bettxid\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5435,7 +5463,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue tokentransfer(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); std::string hex; uint64_t amount; uint256 tokenid;
|
||||
UniValue result(UniValue::VOBJ); std::string hex; int64_t amount; uint256 tokenid;
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("tokentransfer tokenid destpubkey amount\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5446,17 +5474,21 @@ UniValue tokentransfer(const UniValue& params, bool fHelp)
|
||||
std::vector<unsigned char> pubkey(ParseHex(params[1].get_str().c_str()));
|
||||
amount = atol(params[2].get_str().c_str());
|
||||
hex = AssetTransfer(0,tokenid,pubkey,amount);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt transfer assets"));
|
||||
if (amount > 0) {
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt transfer assets"));
|
||||
} else {
|
||||
ERR_RESULT("amount must be positive");
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue tokenbid(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid;
|
||||
UniValue result(UniValue::VOBJ); int64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid;
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("tokenbid numtokens tokenid price\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5468,11 +5500,15 @@ UniValue tokenbid(const UniValue& params, bool fHelp)
|
||||
price = atof(params[2].get_str().c_str());
|
||||
bidamount = (price * numtokens) * COIN + 0.0000000049999;
|
||||
hex = CreateBuyOffer(0,bidamount,tokenid,numtokens);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create bid"));
|
||||
if (price > 0 && numtokens > 0) {
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create bid"));
|
||||
} else {
|
||||
ERR_RESULT("price and numtokens must be positive");
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
@@ -5519,7 +5555,7 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue tokenask(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint64_t askamount,numtokens; std::string hex; double price; uint256 tokenid;
|
||||
UniValue result(UniValue::VOBJ); int64_t askamount,numtokens; std::string hex; double price; uint256 tokenid;
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("tokenask numtokens tokenid price\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5531,18 +5567,22 @@ UniValue tokenask(const UniValue& params, bool fHelp)
|
||||
price = atof(params[2].get_str().c_str());
|
||||
askamount = (price * numtokens) * COIN + 0.0000000049999;
|
||||
hex = CreateSell(0,numtokens,tokenid,askamount);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create ask"));
|
||||
if (price > 0 && numtokens > 0) {
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create ask"));
|
||||
} else {
|
||||
ERR_RESULT("price and numtokens must be positive");
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue tokenswapask(const UniValue& params, bool fHelp)
|
||||
{
|
||||
static uint256 zeroid;
|
||||
UniValue result(UniValue::VOBJ); uint64_t askamount,numtokens; std::string hex; double price; uint256 tokenid,otherid;
|
||||
UniValue result(UniValue::VOBJ); int64_t askamount,numtokens; std::string hex; double price; uint256 tokenid,otherid;
|
||||
if ( fHelp || params.size() != 4 )
|
||||
throw runtime_error("tokenswapask numtokens tokenid otherid price\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5555,11 +5595,15 @@ UniValue tokenswapask(const UniValue& params, bool fHelp)
|
||||
price = atof(params[3].get_str().c_str());
|
||||
askamount = (price * numtokens);
|
||||
hex = CreateSwap(0,numtokens,tokenid,otherid,askamount);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create swap"));
|
||||
if (price > 0 && numtokens > 0) {
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create swap"));
|
||||
} else {
|
||||
ERR_RESULT("price and numtokens must be positive");
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
@@ -5597,18 +5641,22 @@ UniValue tokenfillask(const UniValue& params, bool fHelp)
|
||||
asktxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
fillunits = atol(params[2].get_str().c_str());
|
||||
hex = FillSell(0,tokenid,zeroid,asktxid,fillunits);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt fill bid"));
|
||||
if (fillunits > 0) {
|
||||
if ( hex.size() > 0)
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else ERR_RESULT("couldnt fill bid");
|
||||
} else {
|
||||
ERR_RESULT("fillunits must be positive");
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue tokenfillswap(const UniValue& params, bool fHelp)
|
||||
{
|
||||
static uint256 zeroid;
|
||||
UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,otherid,asktxid;
|
||||
UniValue result(UniValue::VOBJ); int64_t fillunits; std::string hex; uint256 tokenid,otherid,asktxid;
|
||||
if ( fHelp || params.size() != 4 )
|
||||
throw runtime_error("tokenfillswap tokenid otherid asktxid fillunits\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
@@ -5620,11 +5668,14 @@ UniValue tokenfillswap(const UniValue& params, bool fHelp)
|
||||
asktxid = Parseuint256((char *)params[2].get_str().c_str());
|
||||
fillunits = atol(params[3].get_str().c_str());
|
||||
hex = FillSell(0,tokenid,otherid,asktxid,fillunits);
|
||||
if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt fill bid"));
|
||||
if (fillunits > 0) {
|
||||
if ( hex.size() > 0 ) {
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else ERR_RESULT("couldnt fill bid");
|
||||
} else {
|
||||
ERR_RESULT("fillunits must be positive");
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user