AssetXXX() changed to GetTokenBalance, TokenInfo, TokenList
added processing of incorrect tokenid to GetTokenBalance
This commit is contained in:
@@ -6947,7 +6947,7 @@ UniValue tokenlist(const UniValue& params, bool fHelp)
|
||||
throw runtime_error("tokenlist\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
return(AssetList());
|
||||
return(TokenList());
|
||||
}
|
||||
|
||||
UniValue tokeninfo(const UniValue& params, bool fHelp)
|
||||
@@ -6958,7 +6958,7 @@ UniValue tokeninfo(const UniValue& params, bool fHelp)
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
tokenid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
return(AssetInfo(tokenid));
|
||||
return(TokenInfo(tokenid));
|
||||
}
|
||||
|
||||
UniValue tokenorders(const UniValue& params, bool fHelp)
|
||||
@@ -6977,22 +6977,35 @@ UniValue tokenorders(const UniValue& params, bool fHelp)
|
||||
UniValue tokenbalance(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char destaddr[64]; uint256 tokenid; uint64_t balance; std::vector<unsigned char> pubkey; struct CCcontract_info *cp,C;
|
||||
CCerror.clear();
|
||||
|
||||
cp = CCinit(&C,EVAL_ASSETS);
|
||||
if ( fHelp || params.size() > 2 )
|
||||
throw runtime_error("tokenbalance tokenid [pubkey]\n");
|
||||
if ( ensure_CCrequirements() < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
LOCK(cs_main);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
tokenid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
if ( params.size() == 2 )
|
||||
pubkey = ParseHex(params[1].get_str().c_str());
|
||||
else pubkey = Mypubkey();
|
||||
else
|
||||
pubkey = Mypubkey();
|
||||
result.push_back(Pair("result", "success"));
|
||||
if ( GetCCaddress(cp,destaddr,pubkey2pk(pubkey)) != 0 )
|
||||
if (GetCCaddress(cp,destaddr,pubkey2pk(pubkey)) != 0)
|
||||
result.push_back(Pair("CCaddress",destaddr));
|
||||
balance = GetAssetBalance(pubkey2pk(pubkey),tokenid);
|
||||
result.push_back(Pair("tokenid", params[0].get_str()));
|
||||
result.push_back(Pair("balance", (int64_t)balance));
|
||||
|
||||
balance = GetTokenBalance(pubkey2pk(pubkey),tokenid);
|
||||
|
||||
if (CCerror.empty()) {
|
||||
result.push_back(Pair("tokenid", params[0].get_str()));
|
||||
result.push_back(Pair("balance", (int64_t)balance));
|
||||
}
|
||||
else {
|
||||
ERR_RESULT(CCerror);
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user