Test refactoring, more tests, and lots of error checking improvements and uint64_t fixes

This commit is contained in:
Jonathan "Duke" Leto
2018-08-15 23:24:59 +02:00
parent ef44dd00e1
commit 8e0ff2b732
3 changed files with 158 additions and 77 deletions

View File

@@ -46,11 +46,19 @@ class CryptoConditionsTest (BitcoinTestFramework):
]] ]]
) )
self.is_network_split = split self.is_network_split = split
self.rpc = self.nodes[0]
self.sync_all() self.sync_all()
print("Done setting up network") print("Done setting up network")
def send_and_mine(self, xtn):
txid = self.rpc.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
self.rpc.generate(1)
return txid
def run_faucet_tests(self): def run_faucet_tests(self):
rpc = self.nodes[0] rpc = self.rpc
# basic sanity tests # basic sanity tests
result = rpc.getwalletinfo() result = rpc.getwalletinfo()
@@ -90,9 +98,6 @@ class CryptoConditionsTest (BitcoinTestFramework):
# we need the tx above to be confirmed in the next block # we need the tx above to be confirmed in the next block
rpc.generate(1) rpc.generate(1)
# clear the rawmempool
result = rpc.getrawmempool()
result = rpc.getwalletinfo() result = rpc.getwalletinfo()
balance2 = result['balance'] balance2 = result['balance']
# make sure our balance is less now # make sure our balance is less now
@@ -145,13 +150,18 @@ class CryptoConditionsTest (BitcoinTestFramework):
for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']: for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']:
assert_equal(result[x][0], 'R') assert_equal(result[x][0], 'R')
result = rpc.tokencreate("DUKE", "1987.420", "duke")
assert_equal(result['result'], 'success')
# there are no tokens created yet # there are no tokens created yet
result = rpc.tokenlist() result = rpc.tokenlist()
assert_equal(result, []) assert_equal(result, [])
result = rpc.tokencreate("DUKE", "1987.420", "duke")
assert_equal(result['result'], 'success')
self.send_and_mine(result['hex'])
result = rpc.tokenlist()
tokenid = result[0]
assert(tokenid, "got tokenid")
# there are no token orders yet # there are no token orders yet
result = rpc.tokenorders() result = rpc.tokenorders()
assert_equal(result, []) assert_equal(result, [])
@@ -166,6 +176,7 @@ class CryptoConditionsTest (BitcoinTestFramework):
result = rpc.tokeninfo(self.pubkey) result = rpc.tokeninfo(self.pubkey)
assert_equal(result['result'], 'error') assert_equal(result['result'], 'error')
def run_rewards_tests(self): def run_rewards_tests(self):
rpc = self.nodes[0] rpc = self.nodes[0]
result = rpc.rewardsaddress() result = rpc.rewardsaddress()
@@ -272,7 +283,6 @@ class CryptoConditionsTest (BitcoinTestFramework):
print("Importing privkey") print("Importing privkey")
rpc.importprivkey(self.privkey) rpc.importprivkey(self.privkey)
self.run_faucet_tests() self.run_faucet_tests()
self.run_rewards_tests() self.run_rewards_tests()
self.run_dice_tests() self.run_dice_tests()

View File

@@ -66,6 +66,8 @@
*/ */
extern std::string CCerror;
int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit)
{ {
int32_t numblocks; uint64_t duration,reward = 0; int32_t numblocks; uint64_t duration,reward = 0;
@@ -532,6 +534,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2
if ( RewardsPlanExists(cp,sbits,rewardspk,APR,minseconds,maxseconds,mindeposit) == 0 ) if ( RewardsPlanExists(cp,sbits,rewardspk,APR,minseconds,maxseconds,mindeposit) == 0 )
{ {
fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr);
CCerror = "Rewards plan does not exist";
return(""); return("");
} }
fprintf(stderr,"APR %.8f minseconds.%llu maxseconds.%llu mindeposit %.8f\n",(double)APR/COIN,(long long)minseconds,(long long)maxseconds,(double)mindeposit/COIN); fprintf(stderr,"APR %.8f minseconds.%llu maxseconds.%llu mindeposit %.8f\n",(double)APR/COIN,(long long)minseconds,(long long)maxseconds,(double)mindeposit/COIN);
@@ -543,6 +546,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2
if ( (amount= CCutxovalue(coinaddr,locktxid,0)) == 0 ) if ( (amount= CCutxovalue(coinaddr,locktxid,0)) == 0 )
{ {
fprintf(stderr,"%s locktxid/v0 is spent\n",coinaddr); fprintf(stderr,"%s locktxid/v0 is spent\n",coinaddr);
CCerror = "locktxid/v0 is spent";
return(""); return("");
} }
if ( GetTransaction(locktxid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) if ( GetTransaction(locktxid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 )
@@ -553,21 +557,37 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2
else else
{ {
fprintf(stderr,"%s no normal vout.1 in locktxid\n",coinaddr); fprintf(stderr,"%s no normal vout.1 in locktxid\n",coinaddr);
CCerror = "no normal vout.1 in locktxid";
return(""); return("");
} }
} }
if ( amount > 0 && (reward= RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit)) > txfee && scriptPubKey.size() > 0 ) if ( amount > 0 ) {
{ reward = RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit);
if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) if (scriptPubKey.size() > 0) {
{ if (reward > txfee) {
if ( inputs >= (reward + 2*txfee) ) if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 )
CCchange = (inputs - (reward + txfee)); {
fprintf(stderr,"inputs %.8f CCchange %.8f amount %.8f reward %.8f\n",(double)inputs/COIN,(double)CCchange/COIN,(double)amount/COIN,(double)reward/COIN); if ( inputs >= (reward + 2*txfee) )
mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,rewardspk)); CCchange = (inputs - (reward + txfee));
mtx.vout.push_back(CTxOut(amount+reward,scriptPubKey)); fprintf(stderr,"inputs %.8f CCchange %.8f amount %.8f reward %.8f\n",(double)inputs/COIN,(double)CCchange/COIN,(double)amount/COIN,(double)reward/COIN);
return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,EncodeRewardsOpRet('U',sbits,fundingtxid))); mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,rewardspk));
} mtx.vout.push_back(CTxOut(amount+reward,scriptPubKey));
fprintf(stderr,"cant find enough rewards inputs\n"); return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,EncodeRewardsOpRet('U',sbits,fundingtxid)));
}
CCerror = "cant find enough rewards inputs";
fprintf(stderr,"%s\n", CCerror.c_str());
} else {
// strprintf?
CCerror = strprintf("reward %.8f is <= the transaction fee", reward);
fprintf(stderr,"%s\n", CCerror.c_str());
}
} else {
CCerror = "invalid scriptPubKey";
fprintf(stderr,"%s\n", CCerror.c_str());
}
} else {
CCerror = "amount must be positive";
fprintf(stderr,"%s\n", CCerror.c_str());
} }
fprintf(stderr,"amount %.8f -> reward %.8f\n",(double)amount/COIN,(double)reward/COIN); fprintf(stderr,"amount %.8f -> reward %.8f\n",(double)amount/COIN,(double)reward/COIN);
return(""); return("");

View File

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