Add oraclessample rpc to get data for txid.
This commit is contained in:
@@ -26,6 +26,7 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee);
|
||||
std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount);
|
||||
std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector <uint8_t> data);
|
||||
// CCcustom
|
||||
UniValue OracleDataSample(uint256 reforacletxid,uint256 txid);
|
||||
UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num);
|
||||
UniValue OracleInfo(uint256 origtxid);
|
||||
UniValue OraclesList();
|
||||
|
||||
@@ -1059,6 +1059,38 @@ UniValue OracleFormat(uint8_t *data,int32_t datalen,char *format,int32_t formatl
|
||||
return(obj);
|
||||
}
|
||||
|
||||
UniValue OracleDataSample(uint256 reforacletxid,uint256 txid)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; std::string error;
|
||||
CPubKey pk; std::string name,description,format; int32_t numvouts; std::vector<uint8_t> data; char str[67], *formatstr = 0;
|
||||
|
||||
result.push_back(Pair("result","success"));
|
||||
if ( GetTransaction(reforacletxid,oracletx,hashBlock,false) != 0 && (numvouts=oracletx.vout.size()) > 0 )
|
||||
{
|
||||
if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' )
|
||||
{
|
||||
if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 )
|
||||
{
|
||||
if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid )
|
||||
{
|
||||
if ( (formatstr= (char *)format.c_str()) == 0 )
|
||||
formatstr = (char *)"";
|
||||
result.push_back(Pair("txid",uint256_str(str,txid)));
|
||||
result.push_back(Pair("data",OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size())));
|
||||
return(result);
|
||||
}
|
||||
else error="invalid data tx";
|
||||
}
|
||||
else error="cannot find data txid";
|
||||
}
|
||||
else error="invalid oracles txid";
|
||||
}
|
||||
else error="cannot find oracles txid";
|
||||
result.push_back(Pair("result","error"));
|
||||
result.push_back(Pair("error",error));
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ),b(UniValue::VARR); CTransaction tx,oracletx; uint256 txid,hashBlock,btxid,oracletxid;
|
||||
|
||||
@@ -460,6 +460,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "oracles", "oraclesregister", &oraclesregister, true },
|
||||
{ "oracles", "oraclessubscribe", &oraclessubscribe, true },
|
||||
{ "oracles", "oraclesdata", &oraclesdata, true },
|
||||
{ "oracles", "oraclessample", &oraclessample, true },
|
||||
{ "oracles", "oraclessamples", &oraclessamples, true },
|
||||
|
||||
// Prices
|
||||
|
||||
@@ -271,6 +271,7 @@ extern UniValue oraclesfund(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclesregister(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclessubscribe(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclesdata(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclessample(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclessamples(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue priceslist(const UniValue& params, bool fHelp);
|
||||
|
||||
@@ -6830,6 +6830,20 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp)
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue oraclessample(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint256 oracletxid,txid; int32_t num; char *batonaddr;
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("oraclessample oracletxid txid\n");
|
||||
if ( ensure_CCrequirements(EVAL_ORACLES) < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
oracletxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
txid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
return(OracleDataSample(oracletxid,txid));
|
||||
}
|
||||
|
||||
UniValue oraclessamples(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint256 txid; int32_t num; char *batonaddr;
|
||||
|
||||
Reference in New Issue
Block a user