diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index 2f279b1c1..41409d5c5 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -26,6 +26,7 @@ std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,i std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data); // CCcustom +UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num); UniValue OracleInfo(uint256 origtxid); UniValue OraclesList(); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index fd54f924c..a776e50c8 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -66,8 +66,9 @@ struct CC_utxo struct CCcontract_info { uint256 prevtxid; - char unspendableCCaddr[64],CChexstr[72],normaladdr[64]; - uint8_t CCpriv[32]; + char unspendableCCaddr[64],CChexstr[72],normaladdr[64],unspendableaddr2[64]; + uint8_t CCpriv[32],unspendablepriv2[32]; + CPubKey unspendablepk2; bool (*validate)(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); bool (*ismyvin)(CScript const& scriptSig); uint8_t evalcode,didinit; @@ -88,6 +89,8 @@ bool myIsutxo_spentinmempool(uint256 txid,int32_t vout); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); bool mySendrawtransaction(std::string res); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); +int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); +int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp); // CCcustom CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 2c3001c10..79c4572a1 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -41,7 +41,7 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[64],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*cond; CPubKey unspendablepk; + CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[64],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*othercond2=0,*cond; CPubKey unspendablepk; n = mtx.vout.size(); for (i=0; iunspendable2) == 0 ) + { + fprintf(stderr,"matched %s unspendable2!\n",cp->unspendable2); + privkey = cp->unspendablepriv2; + if ( othercond2 == 0 ) + otherconds = MakeCCcond1(cp->evalcode,cp->unspendablepk2); + cond = othercond; + } else { fprintf(stderr,"vini.%d has unknown CC address.(%s)\n",i,destaddr); @@ -136,7 +144,10 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran //fprintf(stderr," signed with privkey\n"); mtx.vin[i].scriptSig = CCSig(cond); } - else fprintf(stderr,"vini.%d has CC signing error address.(%s)\n",i,destaddr); + else + { + fprintf(stderr,"vini.%d has CC signing error address.(%s)\n",i,destaddr); + } } } else fprintf(stderr,"FinalizeCCTx couldnt find %s\n",mtx.vin[i].prevout.hash.ToString().c_str()); } diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index b0ac46cf2..3eecd640b 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -29,6 +29,13 @@ In order to be resistant to sybil attacks, the feedback mechanism needs to have a cost. combining with the idea of payments for data, the oracle providers will be ranked by actual payments made to each oracle for each data type. + Implementation notes: + In order to maintain good performance even under heavy usage, special market utxo are used. Actually a pair of them. When a provider registers to be a data provider, a special unspendable normal output is created to allow for quick scanning. Since the marker is based on the oracletxid, it becomes a single address where all the providers can be found. + + A convention is used so that the datafee can be changed by registering again. it is assumed that there wont be too many of these datafee changes. if more than one from the same provider happens in the same block, the lower price is used. + + The other efficiency issue is finding the most recent data point. We want to create a linked list of all data points, going back to the first one. In order to make this efficient, a special and unique per provider/oracletxid baton utxo is used. This should have exactly one utxo, so the search would be a direct lookup and it is passed on from one data point to the next. There is some small chance that the baton utxo is spent in a non-data transaction, so provision is made to allow for recreating a baton utxo in case it isnt found. The baton utxo is a convenience and doesnt affect validation + Required transactions: 0) create oracle description -> just needs to create txid for oracle data 1) register as oracle data provider with price -> become a registered oracle data provider @@ -44,7 +51,8 @@ register: vins.*: normal inputs vout.0: txfee tag to normal marker address - vout.1: change, if any + vout.1: baton CC utxo + vout.2: change, if any vout.n-1: opreturn with createtxid, pubkey and price per data point subscribe: @@ -55,12 +63,22 @@ data: vin.0: normal input + vin.1: baton CC utxo (most of the time) vin.1+: subscription vout.0 vout.0: change to publishers CC address - vout.1: payment for dataprovider - vout.2: change, if any - vout.n-1: opreturn with data in proper format + vout.1: baton CC utxo + vout.2: payment for dataprovider + vout.3: change, if any + vout.n-1: opreturn with prevbatontxid and data in proper format + data (without payment) + vin.0: normal input + vin.1: baton CC utxo + vout.0: txfee to publishers normal address + vout.1: baton CC utxo + vout.2: change, if any + vout.n-1: opreturn with prevbatontxid and data in proper format + */ // start of consensus code @@ -111,19 +129,19 @@ uint8_t DecodeOraclesOpRet(const CScript &scriptPubKey,uint256 &oracletxid,CPubK return(0); } -CScript EncodeOraclesData(uint8_t funcid,uint256 oracletxid,CPubKey pk,std::vector data) +CScript EncodeOraclesData(uint8_t funcid,uint256 oracletxid,uint256 batontxid,CPubKey pk,std::vector data) { CScript opret; uint8_t evalcode = EVAL_ORACLES; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << oracletxid << pk << data); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << oracletxid << batontxid << pk << data); return(opret); } -uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,CPubKey &pk,std::vector &data) +uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint256 &batontxid,CPubKey &pk,std::vector &data) { std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 1 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> oracletxid; ss >> pk; ss >> data) != 0 ) + if ( vopret.size() > 1 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> oracletxid; ss >> batontxid; ss >> pk; ss >> data) != 0 ) { if ( e == EVAL_ORACLES && f == 'D' ) return(f); @@ -131,6 +149,112 @@ uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,CPubKe return(0); } +CPubKey OracleBatonPk(char *batonaddr,struct CCcontract_info *cp,CPubKey mypk) +{ + CPubKey batonpk; CKey key; std::vector vchTmp; uint8_t *ptr,priv[32]; int32_t i; + Myprivkey(priv); + vchTmp.resize(32); + ptr = vchTmp.data(); + for (i=0; i<32; i++) + { + ptr[i] = (priv[i] ^ cp->CCpriv[i]); + cp->unspendablepriv2[i] = ptr[i]; + } + CPrivKey vchPrivKey(vchTmp.begin(), vchTmp.end()); + if (!key.SetPrivKey(vchPrivKey, false)) + { + printf("ThreadSendAlert() : key.SetPrivKey failed\n"); + return; + } + batonpk = cp->unspendablepk2 = key.GetPubKey(); + Getscriptaddress(batonaddr,CScript() << ParseHex(HexStr(batonpk)) << OP_CHECKSIG); + strcpy(cp->unspendableaddr2,batonaddr); + return(batonpk); +} + +int64_t OracleCurrentDatafee(uint256 reforacletxid,char *markeraddr,CPubKey publisher) +{ + uint256 txid,oracletxid; int64_t datafee=0,dfee; int32_t dheight=0,vout,height,numvouts; CTransaction tx; CPubKey pk; + std::vector > unspentOutputs; + SetCCunspents(unspentOutputs,markeraddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + height = (int32_t)it->first.blockHeight; + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + { + if ( DecodeOraclesOpRet(tx.vout[numvouts-1].scriptPubKey,oracletxid,pk,dfee) == 'R' ) + { + if ( oracletxid == reforacletxid && pk == publisher ) + { + if ( height > dheight || (height == dheight && dfee < datafee) ) + { + dheight = height; + datafee = dfee; + fprintf(stderr,"set datafee %.8f height.%d\n",(double)datafee/COIN,height); + } + } + } + } + } + return(datafee); +} + +uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher) +{ + uint256 txid,oracletxid,btxid,batontxid = zeroid; int64_t dfee; int32_t dheight=0,vout,height,numvouts; CTransaction tx; CPubKey pk; uint8_t *ptr; std::vector vopret,data; + std::vector > unspentOutputs; + SetCCunspents(unspentOutputs,batonaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + height = (int32_t)it->first.blockHeight; + if ( it->second.satoshis != txfee ) + continue; + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + { + GetOpReturnData(tx.vout[numvouts-1].scriptPubKey.scriptPubKey,vopret); + if ( vopret.size() > 2 ) + { + ptr = (uint8_t *)vopret.data(); + if ( (ptr[1] == 'R' && DecodeOraclesOpRet(tx.vout[numvouts-1].scriptPubKey,oracletxid,pk,dfee) == 'R') || (ptr[1] == 'D' && DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D') ) + { + if ( oracletxid == reforacletxid && pk == publisher ) + { + if ( height > dheight ) + { + dheight = height; + batontxid = txid; + char str[65]; fprintf(stderr,"set batontxid %s height.%d\n",uint256_str(str,batontxid),height); + } + } + } + } + } + } + return(batontxid); +} + +int64_t OracleDatafee(CScript &scriptPubKey,uint256 oracletxid,CPubKey publisher) +{ + CTransaction oracletx; char markeraddr[64]; CPubKey markerpubkey; uint8_t buf33[33]; uint256 hashBlock; std::string name,description,format; int32_t numvouts; int64_t datafee = 0; + if ( GetTransaction(oracletxid,oracletx,hashBlock,false) != 0 && (numvouts= oracletx.vout.size()) > 0 ) + { + if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' ) + { + buf33[0] = 0x02; + endiancpy(&buf33[1],(uint8_t *)&oracletxid,32); + markerpubkey = buf2pk(buf33); + scriptPubKey = CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG; + Getscriptaddress(markeraddr,scriptPubKey); + datafee = OracleCurrentDatafee(oracletxid,markeraddr,publisher); + } + } + return(datafee); +} + int64_t IsOraclesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; @@ -270,24 +394,6 @@ int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubK return(total); } -int64_t OracleDatafee(CScript &scriptPubKey,uint256 oracletxid,CPubKey pk) -{ - CTransaction oracletx; char markeraddr[64]; CPubKey markerpubkey; uint8_t buf33[33]; uint256 hashBlock; std::string name,description,format; int32_t numvouts; int64_t datafee = 0; - if ( GetTransaction(oracletxid,oracletx,hashBlock,false) != 0 && (numvouts= oracletx.vout.size()) > 0 ) - { - if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' ) - { - buf33[0] = 0x02; - endiancpy(&buf33[1],(uint8_t *)&oracletxid,32); - markerpubkey = buf2pk(buf33); - scriptPubKey = CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG; - Getscriptaddress(markeraddr,scriptPubKey); - // scan marker tx to get latest datafee - } - } - return(datafee); -} - std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format) { CMutableTransaction mtx; CPubKey mypk,Oraclespk; struct CCcontract_info *cp,C; @@ -311,7 +417,7 @@ std::string OracleCreate(int64_t txfee,std::string name,std::string description, std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) { - CMutableTransaction mtx; CPubKey mypk,markerpubkey; struct CCcontract_info *cp,C; uint8_t buf33[33]; char markeraddr[64]; + CMutableTransaction mtx; CPubKey mypk,markerpubkey,batonpk; struct CCcontract_info *cp,C; uint8_t buf33[33]; char markeraddr[64],batonaddr[64]; cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -320,9 +426,11 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) endiancpy(&buf33[1],(uint8_t *)&oracletxid,32); markerpubkey = buf2pk(buf33); Getscriptaddress(markeraddr,CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG); - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + batonpk = OracleBatonPk(batonaddr,cp,mypk); + if ( AddNormalinputs(mtx,mypk,3*txfee,4) > 0 ) { mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,batonpk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesOpRet('R',oracletxid,mypk,datafee))); } return(""); @@ -350,7 +458,7 @@ std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,i std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data) { - CMutableTransaction mtx; CScript pubKey; CPubKey mypk; int64_t datafee,inputs,CCchange = 0; struct CCcontract_info *cp,C; char coinaddr[64]; + CMutableTransaction mtx; CScript pubKey; CPubKey mypk,batonpk; int64_t datafee,inputs,CCchange = 0; struct CCcontract_info *cp,C; uint256 batontxid; char coinaddr[64],batonaddr[64]; cp = CCinit(&C,EVAL_ORACLES); mypk = pubkey2pk(Mypubkey()); if ( data.size() > 8192 ) @@ -366,23 +474,132 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector da if ( txfee == 0 ) txfee = 10000; GetCCaddress(cp,coinaddr,mypk); - if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) // have enough funds even if baton utxo not there { + batonpk = OracleBatonPk(batonaddr,cp,mypk); + batontxid = OracleBatonUtxo(txfee,cp,oracletxid,batonaddr,mypk); + if ( batontxid != zeroid ) // not impossible to fail, but hopefully a very rare event + mtx.vin.push_back(CTxIn(batontxid,1,CScript())); + else fprintf(stderr,"warning: couldnt find baton utxo\n"); if ( (inputs= AddOracleInputs(cp,mtx,mypk,datafee,60)) > 0 ) { if ( inputs > datafee ) CCchange = (inputs - datafee); mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,mypk)); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesData('D',oracletxid,mypk,data))); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,batonpk)); + mtx.vout.push_back(CTxOut(datafee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesData('D',oracletxid,batontxid,mypk,data))); } } return(""); } +int32_t oracle_format(char *str,uint8_t fmt,uint8_t *data,int32_t offset,int32_t datalen) +{ + int32_t sflag = 0,i,val32,len = 0,slen = 0; uint32_t uval32; uint16_t uval16; int16_t val16; int64 val = 0; uint64_t uval = 0; + switch ( fmt ) + { + case 's': slen = data[offset++]; break; + case 'S': slen = data[offset++]; slen |= ((int32_t)data[offset++] << 8); break; + case 'c': len = 1; sflag = 1; break; + case 'C': len = 1; break; + case 't': len = 2; sflag = 1; break; + case 'T': len = 2; break; + case 'i': len = 4; sflag = 1; break; + case 'I': len = 4; break; + case 'l': len = 8; sflag = 1; break; + case 'L': len = 8; break; + default: return(-1); break; + } + if ( slen != 0 ) + { + for (i=0; i= datalen ) + { + str[i] = 0; + return(-1); + } + } + str[i] = 0; + } + else if ( len != 0 && len+offset <= datalen ) + { + if ( sflag != 0 ) + { + switch ( len ) + { + case 1: val = (int8_t)data[offset]; break; + case 2: iguana_rwnum(0,&data[offset],len,(void *)&val16); val = val16; break; + case 4: iguana_rwnum(0,&data[offset],len,(void *)&val32); val = val32; break; + case 8: iguana_rwnum(0,&data[offset],len,(void *)&val); break; + } + sprintf(str,"%lld",(long long)val); + } + else + { + switch ( len ) + { + case 1: uval = data[offset]; break; + case 2: iguana_rwnum(0,&data[offset],len,(void *)&uval16); uval = uval16; break; + case 4: iguana_rwnum(0,&data[offset],len,(void *)&uval32); uval = uval32; break; + case 8: iguana_rwnum(0,&data[offset],len,(void *)&uval); break; + } + sprintf(str,"%llu",(long long)uval); + } + offset += len; + } else return(-1); + return(offset); +} + +UniValue OracleFormat(uint8_t *data,int32_t datalen,char *format,int32_t formatlen) +{ + UniValue obj(UniValue::VARR); int32_t i,j=0; int64_t val; char str[16384]; + for (i=0; i= datalen ) + break; + } + return(obj); +} + +UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) +{ + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,oracletx; uint256 hashBlock,btxid; CPubKey pk; std::string name,description,format; int32_t numvouts,n=0; std::vector data; char *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' ) + { + while ( GetTransaction(batontxid,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 = ""; + a.push_back(OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size())); + batontxid = btxid; + if ( ++n >= num ) + break; + } else break; + } + } + } + result.push_back(Pair("samples",a)); + return(result); +} + UniValue OracleInfo(uint256 origtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR),obj(UniValue::VOBJ); std::vector > addressIndex; CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid; CMutableTransaction mtx; CPubKey Oraclespk,markerpubkey,pk; struct CCcontract_info *cp,C; uint8_t buf33[33]; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64]; + UniValue result(UniValue::VOBJ),a(UniValue::VARR),obj(UniValue::VOBJ); + std::vector > unspentOutputs; + CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CMutableTransaction mtx; CPubKey Oraclespk,markerpubkey,pk; struct CCcontract_info *cp,C; uint8_t buf33[33]; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; cp = CCinit(&C,EVAL_ORACLES); Oraclespk = GetUnspendable(cp,0); buf33[0] = 0x02; @@ -393,19 +610,25 @@ UniValue OracleInfo(uint256 origtxid) { if ( tx.vout.size() > 0 && DecodeOraclesCreateOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,name,description,format) == 'C' ) { + result.push_back(Pair("result","success")); result.push_back(Pair("txid",uint256_str(str,origtxid))); result.push_back(Pair("name",name)); result.push_back(Pair("description",description)); + result.push_back(Pair("format",format)); result.push_back(Pair("marker",markeraddr)); - SetCCtxids(addressIndex,markeraddr); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + SetCCunspents(unspentOutputs,markeraddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; if ( GetTransaction(txid,regtx,hashBlock,false) != 0 ) { if ( regtx.vout.size() > 0 && DecodeOraclesOpRet(regtx.vout[regtx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R' && oracletxid == origtxid ) { - result.push_back(Pair("provider",pubkey33_str(str,(uint8_t *)pk.begin()))); + obj.push_back(Pair("provider",pubkey33_str(str,(uint8_t *)pk.begin()))); + Getscriptaddress(batonaddr,regtx.vout[1].scriptPubKey); + batontxid = OracleBatonUtxo(10000,cp,oracletxid,batonaddr,pk); + obj.push_back(Pair("baton",batonaddr)); + obj.push_back(Pair("batontxid",uint256_str(str,batontxid))); funding = LifetimeOraclesFunds(cp,oracletxid,pk); sprintf(numstr,"%.8f",(double)funding/COIN); obj.push_back(Pair("lifetime",numstr)); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 9e2c1ded2..092f2b9e5 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -393,6 +393,7 @@ static const CRPCCommand vRPCCommands[] = { "oracles", "oraclesregister", &oraclesregister, true }, { "oracles", "oraclessubscribe", &oraclessubscribe, true }, { "oracles", "oraclesdata", &oraclesdata, true }, + { "oracles", "oraclessamples", &oraclessamples, true }, /* Prices */ { "prices", "pricesaddress", &pricesaddress, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 354ecabea..1cc68798c 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -230,6 +230,7 @@ extern UniValue oraclescreate(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 oraclessamples(const UniValue& params, bool fHelp); extern UniValue pricesaddress(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue triggersaddress(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index aac5e1397..4e0986502 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5419,7 +5419,26 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt register with oracle txid"); + } else ERR_RESULT("couldnt subscribe with oracle txid"); + return(result); +} + +UniValue oraclessamples(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 txid; int32_t num; std::string hex; + if ( fHelp || params.size() != 3 ) + throw runtime_error("oraclessamples oracletxid batonutxo num\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"); + txid = Parseuint256((char *)params[0].get_str().c_str()); + batontxid = Parseuint256((char *)params[1].get_str().c_str()); + num = atoi((char *)params[2].get_str().c_str()); + hex = OracleDataSamples(0,txid,batontxid,num); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt oraclessamples with oracle txid"); return(result); }