]> Git Repo - VerusCoin.git/blobdiff - src/rpcblockchain.cpp
test
[VerusCoin.git] / src / rpcblockchain.cpp
index 81370d0b170bf2a6e5a77533e60d8730f5cdcbbd..ae9f4154043f88645634bfce00a36df2a30f4f56 100644 (file)
@@ -382,25 +382,131 @@ 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(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume);
+int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel);
+int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height);
+char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
+uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n);
+
+Value notaries(const Array& params, bool fHelp)
+{
+    Array a; Object ret; int32_t i,j,n,m; char *hexstr;  uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr;
+    if ( fHelp || params.size() != 1 )
+        throw runtime_error("notaries height\n");
+    LOCK(cs_main);
+    int32_t height = atoi(params[0].get_str().c_str());
+    if ( height < 0 )
+        height = 0;
+    //fprintf(stderr,"notaries as of height.%d\n",height);
+    if ( height > chainActive.Height()+20000 )
+        throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
+    else
+    {
+        if ( (n= komodo_notaries(pubkeys,height)) > 0 )
+        {
+            for (i=0; i<n; i++)
+            {
+                Object item;
+                std::string btcaddress,kmdaddress,hex;
+                hex.resize(66);
+                hexstr = (char *)hex.data();
+                for (j=0; j<33; j++)
+                    sprintf(&hexstr[j*2],"%02x",pubkeys[i][j]);
+                item.push_back(Pair("pubkey", hex));
+
+                bitcoin_address(btcaddr,0,pubkeys[i],33);
+                m = (int32_t)strlen(btcaddr);
+                btcaddress.resize(m);
+                ptr = (char *)btcaddress.data();
+                memcpy(ptr,btcaddr,m);
+                item.push_back(Pair("BTCaddress", btcaddress));
+
+                bitcoin_address(kmdaddr,60,pubkeys[i],33);
+                m = (int32_t)strlen(kmdaddr);
+                kmdaddress.resize(m);
+                ptr = (char *)kmdaddress.data();
+                memcpy(ptr,kmdaddr,m);
+                item.push_back(Pair("KMDaddress", kmdaddress));
+                a.push_back(item);
+            }
+        }
+        ret.push_back(Pair("notaries", a));
+    }
+    return ret;
+}
 
 Value paxprice(const Array& params, bool fHelp)
 {
-    if ( fHelp || params.size() != 3 )
-        throw runtime_error("paxprice \"base\" \"rel\" height\n");
+    if ( fHelp || params.size() < 3 || params.size() > 4 )
+        throw runtime_error("paxprice \"base\" \"rel\" height amount\n");
     LOCK(cs_main);
-    Object ret; uint64_t pricetoshis;
+    Object ret; uint64_t basevolume=0,relvolume,seed;
     std::string base = params[0].get_str();
     std::string rel = params[1].get_str();
-    int height = atoi(params[2].get_str().c_str());
-    pricetoshis = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str());
+    int32_t height = atoi(params[2].get_str().c_str());
+    if ( params.size() == 3 || (basevolume= COIN * atof(params[3].get_str().c_str())) == 0 )
+        basevolume = COIN;
+    relvolume = komodo_paxprice(&seed,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)));
+    char seedstr[32];
+    sprintf(seedstr,"%llu",(long long)seed);
+    ret.push_back(Pair("seed", seedstr));
+    if ( height < 0 || height > chainActive.Height() )
+        throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
+    else
+    {
+        CBlockIndex *pblockindex = chainActive[height];
+        ret.push_back(Pair("timestamp", (int64_t)pblockindex->nTime));
+        if ( basevolume != 0 && relvolume != 0 )
+        {
+            ret.push_back(Pair("price",((double)relvolume / (double)basevolume)));
+            ret.push_back(Pair("invprice",((double)basevolume / (double)relvolume)));
+            ret.push_back(Pair("basevolume", ValueFromAmount(basevolume)));
+            ret.push_back(Pair("relvolume", ValueFromAmount(relvolume)));
+        } else ret.push_back(Pair("error", "overflow or error in one or more of parameters"));
+    }
+    return ret;
+}
+
+Value paxprices(const Array& params, bool fHelp)
+{
+    if ( fHelp || params.size() != 3 )
+        throw runtime_error("paxprices \"base\" \"rel\" maxsamples\n");
+    LOCK(cs_main);
+    Object ret; uint64_t relvolume,prices[4096]; uint32_t i,n; int32_t heights[sizeof(prices)/sizeof(*prices)];
+    std::string base = params[0].get_str();
+    std::string rel = params[1].get_str();
+    int32_t maxsamples = atoi(params[2].get_str().c_str());
+    if ( maxsamples < 1 )
+        maxsamples = 1;
+    else if ( maxsamples > sizeof(heights)/sizeof(*heights) )
+        maxsamples = sizeof(heights)/sizeof(*heights);
+    ret.push_back(Pair("base", base));
+    ret.push_back(Pair("rel", rel));
+    n = komodo_paxprices(heights,prices,maxsamples,(char *)base.c_str(),(char *)rel.c_str());
+    Array a;
+    for (i=0; i<n; i++)
+    {
+        Object item;
+        if ( heights[i] < 0 || heights[i] > chainActive.Height() )
+            throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
+        else
+        {
+            CBlockIndex *pblockindex = chainActive[heights[i]];
+            
+            item.push_back(Pair("t", (int64_t)pblockindex->nTime));
+            item.push_back(Pair("p", (double)prices[i] / COIN));
+            a.push_back(item);
+        }
+    }
+    ret.push_back(Pair("array", a));
     return ret;
 }
 
+uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue);
+
 Value gettxout(const Array& params, bool fHelp)
 {
     if (fHelp || params.size() < 2 || params.size() > 3)
@@ -471,15 +577,9 @@ Value gettxout(const Array& params, bool fHelp)
         ret.push_back(Pair("confirmations", 0));
     else ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1));
     ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue)));
-    
-    CBlockIndex *pblockindex = chainActive[coins.nHeight];
-    uint64_t interest; uint32_t timestamp=0;
-    if ( pblockindex != 0 )
-        timestamp = pblockindex->nTime; // this is approx, but cant figure out how to get tx here
-    interest = komodo_interest(coins.nHeight,coins.vout[n].nValue,timestamp,pindex->nTime);
-    //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest);
-    ret.push_back(Pair("interest", ValueFromAmount(interest)));
-
+    uint64_t interest; int32_t txheight; uint32_t locktime;
+    if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue)) != 0 )
+        ret.push_back(Pair("interest", ValueFromAmount(interest)));
     Object o;
     ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true);
     ret.push_back(Pair("scriptPubKey", o));
This page took 0.023958 seconds and 4 git commands to generate.