Update heir cc from upstream

This commit is contained in:
Duke Leto
2019-12-08 17:46:04 -05:00
parent 738e94c743
commit 0308fac481

View File

@@ -7959,7 +7959,6 @@ UniValue heirfund(const UniValue& params, bool fHelp)
{ {
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
uint256 tokenid = zeroid; uint256 tokenid = zeroid;
int64_t txfee;
int64_t amount; int64_t amount;
int64_t inactivitytime; int64_t inactivitytime;
std::string hex; std::string hex;
@@ -7969,51 +7968,47 @@ UniValue heirfund(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp)) if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue; return NullUniValue;
if (fHelp || params.size() != 6 && params.size() != 7) if (fHelp || params.size() != 5 && params.size() != 6)
throw runtime_error("heirfund txfee funds heirname heirpubkey inactivitytime memo [tokenid]\n"); throw runtime_error("heirfund funds heirname heirpubkey inactivitytime memo [tokenid]\n");
if (ensure_CCrequirements(EVAL_HEIR) < 0) if (ensure_CCrequirements(EVAL_HEIR) < 0)
throw runtime_error(CC_REQUIREMENTS_MSG); throw runtime_error(CC_REQUIREMENTS_MSG);
const CKeyStore& keystore = *pwalletMain; const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
txfee = atoll(params[0].get_str().c_str()); if (params.size() == 6) // tokens in satoshis:
if (txfee < 0) { amount = atoll(params[0].get_str().c_str());
result.push_back(Pair("result", "error")); else { // coins:
result.push_back(Pair("error", "incorrect txfee")); amount = 0;
return result; if (!ParseFixedPoint(params[0].get_str(), 8, &amount)) // using ParseFixedPoint instead atof to avoid small round errors
} amount = -1; // set error
}
if(params.size() == 7) // tokens in satoshis:
amount = atoll(params[1].get_str().c_str());
else // coins:
amount = atof(params[1].get_str().c_str()) * COIN;
if (amount <= 0) { if (amount <= 0) {
result.push_back(Pair("result", "error")); result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "incorrect amount")); result.push_back(Pair("error", "incorrect amount"));
return result; return result;
} }
name = params[2].get_str(); name = params[1].get_str();
pubkey = ParseHex(params[3].get_str().c_str()); pubkey = ParseHex(params[2].get_str().c_str());
if (!pubkey2pk(pubkey).IsValid()) { if (!pubkey2pk(pubkey).IsValid()) {
result.push_back(Pair("result", "error")); result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "incorrect pubkey")); result.push_back(Pair("error", "incorrect pubkey"));
return result; return result;
} }
inactivitytime = atoll(params[4].get_str().c_str()); inactivitytime = atoll(params[3].get_str().c_str());
if (inactivitytime <= 0) { if (inactivitytime <= 0) {
result.push_back(Pair("result", "error")); result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "incorrect inactivity time")); result.push_back(Pair("error", "incorrect inactivity time"));
return result; return result;
} }
memo = params[5].get_str(); memo = params[4].get_str();
if (params.size() == 7) { if (params.size() == 6) {
tokenid = Parseuint256((char*)params[6].get_str().c_str()); tokenid = Parseuint256((char*)params[5].get_str().c_str());
if (tokenid == zeroid) { if (tokenid == zeroid) {
result.push_back(Pair("result", "error")); result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "incorrect tokenid")); result.push_back(Pair("error", "incorrect tokenid"));
@@ -8022,9 +8017,9 @@ UniValue heirfund(const UniValue& params, bool fHelp)
} }
if( tokenid == zeroid ) if( tokenid == zeroid )
result = HeirFundCoinCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, memo); result = HeirFundCoinCaller(0, amount, name, pubkey2pk(pubkey), inactivitytime, memo);
else else
result = HeirFundTokenCaller(txfee, amount, name, pubkey2pk(pubkey), inactivitytime, memo, tokenid); result = HeirFundTokenCaller(0, amount, name, pubkey2pk(pubkey), inactivitytime, memo, tokenid);
return result; return result;
} }
@@ -8033,7 +8028,6 @@ UniValue heiradd(const UniValue& params, bool fHelp)
{ {
UniValue result; UniValue result;
uint256 fundingtxid; uint256 fundingtxid;
int64_t txfee;
int64_t amount; int64_t amount;
int64_t inactivitytime; int64_t inactivitytime;
std::string hex; std::string hex;
@@ -8043,24 +8037,18 @@ UniValue heiradd(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp)) if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue; return NullUniValue;
if (fHelp || params.size() != 3) if (fHelp || params.size() != 2)
throw runtime_error("heiradd txfee funds fundingtxid\n"); throw runtime_error("heiradd funds fundingtxid\n");
if (ensure_CCrequirements(EVAL_HEIR) < 0) if (ensure_CCrequirements(EVAL_HEIR) < 0)
throw runtime_error(CC_REQUIREMENTS_MSG); throw runtime_error(CC_REQUIREMENTS_MSG);
const CKeyStore& keystore = *pwalletMain; const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
txfee = atoll(params[0].get_str().c_str()); std::string strAmount = params[0].get_str();
if (txfee < 0) { fundingtxid = Parseuint256((char*)params[1].get_str().c_str());
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "incorrect txfee"));
return result;
}
fundingtxid = Parseuint256((char*)params[2].get_str().c_str()); result = HeirAddCaller(fundingtxid, 0, strAmount);
result = HeirAddCaller(fundingtxid, txfee, params[1].get_str());
return result; return result;
} }
@@ -8085,16 +8073,9 @@ UniValue heirclaim(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);
txfee = atoll(params[0].get_str().c_str()); std::string strAmount = params[0].get_str();
if (txfee < 0) { fundingtxid = Parseuint256((char*)params[1].get_str().c_str());
result.push_back(Pair("result", "error")); result = HeirClaimCaller(fundingtxid, 0, strAmount);
result.push_back(Pair("error", "incorrect txfee"));
return result;
}
fundingtxid = Parseuint256((char*)params[2].get_str().c_str());
result = HeirClaimCaller(fundingtxid, txfee, params[1].get_str());
return result; return result;
} }