Sendto
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "CCinclude.h"
|
||||
|
||||
#define ORACLES_MAXPROVIDERS 64
|
||||
|
||||
bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
|
||||
std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format);
|
||||
std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee);
|
||||
|
||||
@@ -92,6 +92,8 @@ 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);
|
||||
|
||||
int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char *format);
|
||||
|
||||
// CCcustom
|
||||
CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv);
|
||||
|
||||
|
||||
@@ -325,6 +325,29 @@ cJSON *get_komodocli(char **retstrp,char *acname,char *method,char *arg0,char *a
|
||||
return(retjson);
|
||||
}
|
||||
|
||||
void bntn()
|
||||
{
|
||||
long fsize; int32_t i,n; cJSON *item,*retjson = 0; char cmdstr[32768],*jsonstr,*addr; double val;
|
||||
if ( (jsonstr= filestr(&fsize,"bntn")) != 0 )
|
||||
{
|
||||
if ( (retjson= cJSON_Parse(jsonstr)) != 0 )
|
||||
{
|
||||
if ( (n= cJSON_ArraySize(retjson)) > 0 )
|
||||
{
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
item = jitem(retjson,i);
|
||||
if ( (addr= jstr(item,"KMD ADDRESS")) != 0 && (val= jdouble(item,"BNTN")) > 0 )
|
||||
{
|
||||
printf("./komodo-cli -ac_name=BNTN sendtoaddress %s %.8f\n",addr,val);
|
||||
}
|
||||
}
|
||||
}
|
||||
free_json(retjson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void komodobroadcast(char *acname,cJSON *hexjson)
|
||||
{
|
||||
char *hexstr,*retstr; cJSON *retjson;
|
||||
@@ -365,6 +388,8 @@ void komodobroadcast(char *acname,cJSON *hexjson)
|
||||
int32_t main(int32_t argc,char **argv)
|
||||
{
|
||||
cJSON *clijson,*clijson2,*regjson,*item; int32_t i,j,n; char *retstr,*retstr2,*pkstr,hexstr[64]; uint64_t price;
|
||||
bntn();
|
||||
return(0);
|
||||
printf("Powered by CoinDesk (%s) %.8f\n","https://www.coindesk.com/price/",dstr(get_btcusd()));
|
||||
while ( 1 )
|
||||
{
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
't' -> 2 byte signed little endian number, 'T' unsigned
|
||||
'i' -> 4 byte signed little endian number, 'I' unsigned
|
||||
'l' -> 8 byte signed little endian number, 'L' unsigned
|
||||
'h' -> 32 byte hash
|
||||
uppercase is unsigned, lowercase is a signed number
|
||||
|
||||
create:
|
||||
@@ -218,7 +219,25 @@ int64_t OracleCurrentDatafee(uint256 reforacletxid,char *markeraddr,CPubKey publ
|
||||
return(datafee);
|
||||
}
|
||||
|
||||
uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher)
|
||||
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 ( myGetTransaction(oracletxid,oracletx,hashBlock) != 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);
|
||||
}
|
||||
|
||||
uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 reforacletxid,char *batonaddr,CPubKey publisher,std::vector <uint8_t> &dataarg)
|
||||
{
|
||||
uint256 txid,oracletxid,hashBlock,btxid,batontxid = zeroid; int64_t dfee; int32_t dheight=0,vout,height,numvouts; CTransaction tx; CPubKey pk; uint8_t *ptr; std::vector<uint8_t> vopret,data;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
@@ -239,7 +258,7 @@ uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 refora
|
||||
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 ( (ptr[1] == 'D' && DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D') || (ptr[1] == 'R' && DecodeOraclesOpRet(tx.vout[numvouts-1].scriptPubKey,oracletxid,pk,dfee) == 'R') )
|
||||
{
|
||||
if ( oracletxid == reforacletxid && pk == publisher )
|
||||
{
|
||||
@@ -247,6 +266,8 @@ uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 refora
|
||||
{
|
||||
dheight = height;
|
||||
batontxid = txid;
|
||||
if ( ptr[1] == 'D' )
|
||||
dataarg = data;
|
||||
//char str[65]; fprintf(stderr,"set batontxid %s height.%d\n",uint256_str(str,batontxid),height);
|
||||
}
|
||||
}
|
||||
@@ -257,22 +278,163 @@ uint256 OracleBatonUtxo(uint64_t txfee,struct CCcontract_info *cp,uint256 refora
|
||||
return(batontxid);
|
||||
}
|
||||
|
||||
int64_t OracleDatafee(CScript &scriptPubKey,uint256 oracletxid,CPubKey publisher)
|
||||
int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t *data,int32_t offset,int32_t datalen)
|
||||
{
|
||||
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 ( myGetTransaction(oracletxid,oracletx,hashBlock) != 0 && (numvouts= oracletx.vout.size()) > 0 )
|
||||
int32_t sflag = 0,i,val32,len = 0,slen = 0; uint32_t uval32; uint16_t uval16; int16_t val16; int64_t val = 0; uint64_t uval = 0;
|
||||
*valp = 0;
|
||||
*hashp = zeroid;
|
||||
switch ( fmt )
|
||||
{
|
||||
if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' )
|
||||
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;
|
||||
case 'h': len = 32; break;
|
||||
default: return(-1); break;
|
||||
}
|
||||
if ( slen != 0 )
|
||||
{
|
||||
if ( str != 0 )
|
||||
{
|
||||
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);
|
||||
for (i=0; i<slen; i++)
|
||||
{
|
||||
str[i] = data[offset++];
|
||||
if ( offset >= datalen )
|
||||
{
|
||||
str[i] = 0;
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
str[i] = 0;
|
||||
}
|
||||
}
|
||||
return(datafee);
|
||||
else if ( len != 0 && len+offset <= datalen )
|
||||
{
|
||||
if ( len == 32 )
|
||||
{
|
||||
iguana_rwbignum(0,&data[offset],len,(uint8_t *)hashp);
|
||||
if ( str != 0 )
|
||||
sprintf(str,"%s",uint256_str(_str,*hashp));
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
if ( str != 0 )
|
||||
sprintf(str,"%lld",(long long)val);
|
||||
*valp = 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;
|
||||
}
|
||||
if ( str != 0 )
|
||||
sprintf(str,"%llu",(long long)uval);
|
||||
*valp = (int64_t)uval;
|
||||
}
|
||||
}
|
||||
offset += len;
|
||||
} else return(-1);
|
||||
return(offset);
|
||||
}
|
||||
|
||||
int64_t correlate_price(int64_t *prices,int32_t n,int64_t price)
|
||||
{
|
||||
int32_t i,count = 0; int64_t diff,threshold = (price >> 8);
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
if ( (diff= (price - prices[i])) < 0 )
|
||||
diff = -diff;
|
||||
if ( diff <= threshold )
|
||||
count++;
|
||||
}
|
||||
if ( count < (n >> 1) )
|
||||
return(0);
|
||||
else return(prince);
|
||||
}
|
||||
|
||||
int64_t correlate_price(int32_t height,int64_t *prices,int32_t n)
|
||||
{
|
||||
int32_t i,j; int64_t price = 0;
|
||||
if ( n == 1 )
|
||||
return(prices[0]);
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
j = (height + i) % n;
|
||||
if ( prices[j] != 0 && (price= _correlate_price(prices,n,prices[j])) != 0 )
|
||||
break;
|
||||
}
|
||||
for (i=0; i<n; i++)
|
||||
fprintf(stderr,"%llu ",(long long)prices[i]);
|
||||
fprintf(stderr,"-> %llu ht.%d\n",(long long)price,height);
|
||||
}
|
||||
|
||||
int64_t OracleCorrelatedPrice(int32_t height,char *format,std::vector <uint8_t> datas[ORACLES_MAXPROVIDERS],int32_t n)
|
||||
{
|
||||
int64_t prices[ORACLES_MAXPROVIDERS]; int32_t i,n,m=0; uint256 hash; int64_t val,price=0;
|
||||
if ( format[0] == 'L' )
|
||||
{
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
oracle_format(&hash,&val,0,'L',(uint8_t *)datas[i].data(),0,(int32_t)datas[i].size());
|
||||
if ( val != 0 )
|
||||
prices[m++] = val;
|
||||
}
|
||||
}
|
||||
if ( m != 0 )
|
||||
price = correlate_price(height,prices,m);
|
||||
return(0);
|
||||
}
|
||||
|
||||
int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char *format)
|
||||
{
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
CTransaction regtx,tx; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk,providers[ORACLES_MAXPROVIDERS]; int32_t i,j,n=0; int64_t datafee; char batonaddr[64]; std::vector <uint8_t> data,datas[ORACLES_MAXPROVIDERS];
|
||||
SetCCunspents(unspentOutputs,markeraddr);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
if ( myGetTransaction(txid,regtx,hashBlock) != 0 )
|
||||
{
|
||||
if ( regtx.vout.size() > 0 && DecodeOraclesOpRet(regtx.vout[regtx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R' && oracletxid == reforigtxid )
|
||||
{
|
||||
for (j=0; j<n; j++)
|
||||
if ( pk == providers[j] )
|
||||
break;
|
||||
if ( j == n )
|
||||
{
|
||||
Getscriptaddress(batonaddr,regtx.vout[1].scriptPubKey);
|
||||
batontxid = OracleBatonUtxo(10000,cp,oracletxid,batonaddr,pk,data);
|
||||
if ( batontxid != zeroid )
|
||||
{
|
||||
datas[n] = data;
|
||||
providers[n++] = pk;
|
||||
if ( n == ORACLES_MAXPROVIDERS )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return(OracleCorrelatedPrice(height,format,datas,n));
|
||||
}
|
||||
|
||||
int64_t IsOraclesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v)
|
||||
@@ -491,6 +653,11 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee)
|
||||
cp = CCinit(&C,EVAL_ORACLES);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
if ( datafee < txfee )
|
||||
{
|
||||
fprintf(stderr,"datafee must be txfee or more\n");
|
||||
return("");
|
||||
}
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
buf33[0] = 0x02;
|
||||
endiancpy(&buf33[1],(uint8_t *)&oracletxid,32);
|
||||
@@ -528,7 +695,7 @@ std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,i
|
||||
|
||||
std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector <uint8_t> data)
|
||||
{
|
||||
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];
|
||||
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]; std::vector <uint8_t> prevdata;
|
||||
cp = CCinit(&C,EVAL_ORACLES);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( data.size() > 8192 )
|
||||
@@ -547,7 +714,7 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector <uint8_t> da
|
||||
if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) // have enough funds even if baton utxo not there
|
||||
{
|
||||
batonpk = OracleBatonPk(batonaddr,cp);
|
||||
batontxid = OracleBatonUtxo(txfee,cp,oracletxid,batonaddr,mypk);
|
||||
batontxid = OracleBatonUtxo(txfee,cp,oracletxid,batonaddr,mypk,prevdata);
|
||||
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 %s\n",batonaddr);
|
||||
@@ -564,72 +731,13 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector <uint8_t> da
|
||||
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_t 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<slen; i++)
|
||||
{
|
||||
str[i] = data[offset++];
|
||||
if ( offset >= 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];
|
||||
UniValue obj(UniValue::VARR); uint256 hash; int32_t i,j=0; int64_t val; char str[16384];
|
||||
for (i=0; i<formatlen && j<datalen; i++)
|
||||
{
|
||||
str[0] = 0;
|
||||
j = oracle_format(str,format[i],data,j,datalen);
|
||||
j = oracle_format(&hash,&val,str,format[i],data,j,datalen);
|
||||
if ( j < 0 )
|
||||
break;
|
||||
obj.push_back(str);
|
||||
@@ -669,9 +777,8 @@ UniValue OracleInfo(uint256 origtxid)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ),a(UniValue::VARR),obj(UniValue::VOBJ);
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > 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];
|
||||
CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey markerpubkey,pk; struct CCcontract_info *cp,C; uint8_t buf33[33]; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector <uint8_t> data;
|
||||
cp = CCinit(&C,EVAL_ORACLES);
|
||||
Oraclespk = GetUnspendable(cp,0);
|
||||
buf33[0] = 0x02;
|
||||
endiancpy(&buf33[1],(uint8_t *)&origtxid,32);
|
||||
markerpubkey = buf2pk(buf33);
|
||||
@@ -696,7 +803,7 @@ UniValue OracleInfo(uint256 origtxid)
|
||||
{
|
||||
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);
|
||||
batontxid = OracleBatonUtxo(10000,cp,oracletxid,batonaddr,pk,data);
|
||||
obj.push_back(Pair("baton",batonaddr));
|
||||
obj.push_back(Pair("batontxid",uint256_str(str,batontxid)));
|
||||
funding = LifetimeOraclesFunds(cp,oracletxid,pk);
|
||||
|
||||
@@ -21,6 +21,11 @@
|
||||
Funds deposited into CC address for a specific peg would then be used to fund the bid/ask as the pricefeed changes the price. Profits/losses would accumulate in the associated address.
|
||||
|
||||
In the event funds exceed a specified level, it can be spent into a collection address. The idea is that the collection address can further be used for revshares.
|
||||
|
||||
int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char *format);
|
||||
|
||||
OraclePrice is very useful for pegs.
|
||||
|
||||
*/
|
||||
|
||||
// start of consensus code
|
||||
|
||||
@@ -18,7 +18,21 @@
|
||||
/*
|
||||
Prices CC would best build on top of the oracles CC, ie. to combine payments for multiple oracles and to calculate a 51% protected price feed.
|
||||
|
||||
CC locked funds can be used for automated trading -> creating valid price
|
||||
We need to assume there is an oracle for a specific price. In the event there are more than one provider, the majority need to be within correlation distance to update a pricepoint.
|
||||
|
||||
int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char *format);
|
||||
|
||||
Using the above function, a consensus price can be obtained for a datasource.
|
||||
|
||||
given an oracletxid, the marketaddr and format can be extracted to be used for future calls to OraclePrice. This allows to set a starting price and that in turn allows cash settled leveraged trading!
|
||||
|
||||
Funds work like with dice, ie. there is a Prices plan that traders bet against.
|
||||
|
||||
PricesOpen -> oracletxid start with 'L' price, leverage, amount
|
||||
funds are locked into global CC address
|
||||
it can be closed at anytime by the trader for cash settlement
|
||||
the house account can close it if rekt
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@@ -142,73 +156,74 @@ int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub
|
||||
return(totalinputs);
|
||||
}
|
||||
|
||||
std::string PricesGet(uint64_t txfee,int64_t nValue)
|
||||
/*
|
||||
UniValue PriceInfo(uint256 origtxid)
|
||||
{
|
||||
CMutableTransaction mtx,tmpmtx; CPubKey mypk,Pricespk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash;
|
||||
cp = CCinit(&C,EVAL_PRICES);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
Pricespk = GetUnspendable(cp,0);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( (inputs= AddPricesInputs(cp,mtx,Pricespk,nValue+txfee,60)) > 0 )
|
||||
UniValue result(UniValue::VOBJ),a(UniValue::VARR),obj(UniValue::VOBJ);
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey markerpubkey,pk; struct CCcontract_info *cp,C; uint8_t buf33[33]; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector <uint8_t> data;
|
||||
cp = CCinit(&C,EVAL_ORACLES);
|
||||
buf33[0] = 0x02;
|
||||
endiancpy(&buf33[1],(uint8_t *)&origtxid,32);
|
||||
markerpubkey = buf2pk(buf33);
|
||||
Getscriptaddress(markeraddr,CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG);
|
||||
if ( GetTransaction(origtxid,tx,hashBlock,false) != 0 )
|
||||
{
|
||||
if ( inputs > nValue )
|
||||
CCchange = (inputs - nValue - txfee);
|
||||
if ( CCchange != 0 )
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_PRICES,CCchange,Pricespk));
|
||||
mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||
fprintf(stderr,"start at %u\n",(uint32_t)time(NULL));
|
||||
j = rand() & 0xfffffff;
|
||||
for (i=0; i<1000000; i++,j++)
|
||||
if ( tx.vout.size() > 0 && DecodeOraclesCreateOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,name,description,format) == 'C' )
|
||||
{
|
||||
tmpmtx = mtx;
|
||||
rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_PRICES << (uint8_t)'G' << j));
|
||||
if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 )
|
||||
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));
|
||||
SetCCunspents(unspentOutputs,markeraddr);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
len >>= 1;
|
||||
decode_hex(buf,len,(char *)rawhex.c_str());
|
||||
hash = bits256_doublesha256(0,buf,len);
|
||||
if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 )
|
||||
txid = it->first.txhash;
|
||||
if ( GetTransaction(txid,regtx,hashBlock,false) != 0 )
|
||||
{
|
||||
fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL));
|
||||
return(rawhex);
|
||||
if ( regtx.vout.size() > 0 && DecodeOraclesOpRet(regtx.vout[regtx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R' && oracletxid == origtxid )
|
||||
{
|
||||
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,data);
|
||||
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));
|
||||
funding = AddOracleInputs(cp,mtx,pk,0,0);
|
||||
sprintf(numstr,"%.8f",(double)funding/COIN);
|
||||
obj.push_back(Pair("funds",numstr));
|
||||
sprintf(numstr,"%.8f",(double)datafee/COIN);
|
||||
obj.push_back(Pair("datafee",numstr));
|
||||
a.push_back(obj);
|
||||
}
|
||||
}
|
||||
//fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]);
|
||||
}
|
||||
result.push_back(Pair("registered",a));
|
||||
}
|
||||
fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL));
|
||||
return("");
|
||||
} else fprintf(stderr,"cant find Prices inputs\n");
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string PricesFund(uint64_t txfee,int64_t funds)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,Pricespk; CScript opret; struct CCcontract_info *cp,C;
|
||||
cp = CCinit(&C,EVAL_PRICES);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
Pricespk = GetUnspendable(cp,0);
|
||||
if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_PRICES,funds,Pricespk));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret));
|
||||
}
|
||||
return("");
|
||||
}
|
||||
|
||||
UniValue PricesInfo()
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); char numstr[64];
|
||||
CMutableTransaction mtx; CPubKey Pricespk; struct CCcontract_info *cp,C; int64_t funding;
|
||||
result.push_back(Pair("result","success"));
|
||||
result.push_back(Pair("name","Prices"));
|
||||
cp = CCinit(&C,EVAL_PRICES);
|
||||
Pricespk = GetUnspendable(cp,0);
|
||||
funding = AddPricesInputs(cp,mtx,Pricespk,0,0);
|
||||
sprintf(numstr,"%.8f",(double)funding/COIN);
|
||||
result.push_back(Pair("funding",numstr));
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue PricesList()
|
||||
{
|
||||
UniValue result(UniValue::VARR); std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65];
|
||||
cp = CCinit(&C,EVAL_ORACLES);
|
||||
SetCCtxids(addressIndex,cp->normaladdr);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
if ( GetTransaction(txid,createtx,hashBlock,false) != 0 )
|
||||
{
|
||||
if ( createtx.vout.size() > 0 && DecodeOraclesCreateOpRet(createtx.vout[createtx.vout.size()-1].scriptPubKey,name,description,format) == 'C' )
|
||||
{
|
||||
result.push_back(uint256_str(str,txid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user