This commit is contained in:
jl777
2016-10-23 14:40:41 -03:00
parent 4a41b0b27b
commit a9869d0dd7
4 changed files with 66 additions and 1 deletions

View File

@@ -45,6 +45,32 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno
#define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9"
char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies
"CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK" };
uint32_t MINDENOMS[] = { 1000, 1000, 100000, 1000, 1000, 1000, 1000, 1000, // major currencies
10000, 100000, 10000, 1000, 100000, 10000, 1000, 10000, 1000, 10000, 10000, 10000, 10000, 100000, 1000, 1000000, 1000, 10000, 1000, 1000, 10000, 1000, 10000000, 10000, // end of currencies
};
uint32_t PAX_val32(double val)
{
uint32_t val32 = 0; struct price_resolution price;
if ( (price.Pval= val*1000000000) != 0 )
{
if ( price.Pval > 0xffffffff )
printf("Pval overflow error %lld\n",(long long)price.Pval);
else val32 = (uint32_t)price.Pval;
}
return(val32);
}
double PAX_val(uint32_t pval,int32_t baseid)
{
if ( baseid >= 0 && baseid < MAX_CURRENCIES )
return(((double)pval / 1000000000.) / MINDENOMS[baseid]);
return(0.);
}
const char *Notaries[][2] =
{
{ "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" },
@@ -446,6 +472,25 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals)
}
}
uint64_t komodo_paxprice(int32_t height,char *base,char *rel)
{
int32_t baseid,relid,i,ht; uint32_t pvalb,pvalr,*ptr;
if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 )
{
for (i=NUM_PRICES-1; i>=0; i--)
{
ptr = &PVALS[36 * i];
if ( *ptr <= height )
{
if ( (pvalb= ptr[baseid]) != 0 && (pvalr= ptr[relid]) != 0 )
return(SATOSHIDEN * (PAX_val(pvalb,baseid) / PAX_val(pvalr,relid)));
return(0);
}
}
}
return(0);
}
int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals)
{
static FILE *fp; static int32_t errs,didinit; char fname[512]; int32_t ht,k,i,func; uint8_t num,pubkeys[64][33];

View File

@@ -382,6 +382,24 @@ 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);
Value paxprice(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 3)
throw runtime_error("paxprice \"base\" \"rel\" height\n");
LOCK(cs_main);
Object ret; uint64_t pricetoshis;
std::string base = params[0].get_str();
std::string rel = params[1].get_str();
int height = params[2].get_int();
pricetoshis = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str());
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)));
return ret;
}
Value gettxout(const Array& params, bool fHelp)
{

View File

@@ -105,7 +105,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "z_sendmany", 2},
{ "z_getoperationstatus", 0},
{ "z_getoperationresult", 0},
{ "z_importkey", 1 }
{ "z_importkey", 1 },
{ "paxprice", 3 },
};
class CRPCConvertTable

View File

@@ -243,6 +243,7 @@ extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fH
extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getchaintips(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value invalidateblock(const json_spirit::Array& params, bool fHelp);