This commit is contained in:
jl777
2016-10-23 16:54:13 -03:00
parent 5a51e22dd1
commit 1f34636377
2 changed files with 38 additions and 12 deletions

View File

@@ -382,22 +382,29 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
uint32_t komodo_txtime(uint256 hash);
uint64_t komodo_paxprice(int32_t height,char *base,char *rel);
uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume);
Value paxprice(const Array& params, bool fHelp)
{
if ( fHelp || params.size() != 3 )
if ( fHelp || params.size() < 3 || params.size() > 4 )
throw runtime_error("paxprice \"base\" \"rel\" height\n");
LOCK(cs_main);
Object ret; uint64_t pricetoshis;
Object ret; uint64_t pricetoshis,basevolume;
std::string base = params[0].get_str();
std::string rel = params[1].get_str();
int32_t height = atoi(params[2].get_str().c_str());
pricetoshis = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str());
if ( params.size() == 3 )
basevolume = COIN;
else basevolume = AmountFromValue(params[3]);
relvolume = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str(),basevolume);
ret.push_back(Pair("base", base));
ret.push_back(Pair("rel", rel));
ret.push_back(Pair("height", height));
ret.push_back(Pair("price", ValueFromAmount(pricetoshis)));
if ( relvolume != 0 )
{
ret.push_back(Pair("price", ValueFromAmount(basevolume) / ValueFromAmount(relvolume)));
ret.push_back(Pair("relvolume", ValueFromAmount(relvolume)));
}
return ret;
}