24
src/cc/dapps/oracle_dapp.sh
Executable file
24
src/cc/dapps/oracle_dapp.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# SET AC
|
||||||
|
read -p "Enter AC name you use : " acname
|
||||||
|
sed -i "/#define ACNAME */c\#define ACNAME \"$acname\"" oraclefeed.c
|
||||||
|
# Set ORACLETXID
|
||||||
|
read -p "Enter your oracle TXID (Oracle should have L data type) : " oracletxid
|
||||||
|
sed -i "/#define ORACLETXID */c\#define ORACLETXID \"$oracletxid\"" oraclefeed.c
|
||||||
|
# SET PUBKEY
|
||||||
|
read -p "Enter your pubkey : " pubkey
|
||||||
|
sed -i "/#define MYPUBKEY */c\#define MYPUBKEY \"$pubkey\"" oraclefeed.c
|
||||||
|
# COMPILATION
|
||||||
|
echo "Great, compiling !"
|
||||||
|
gcc oraclefeed.c -lm -o oracle_dapp
|
||||||
|
mv oracle_dapp ../../oracle_dapp
|
||||||
|
echo "Oracle is ready to use !"
|
||||||
|
while true; do
|
||||||
|
read -p "Would you like to run BTCUSD oracle app? [Y/N]" yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* ) cd ../..; ./oracle_dapp; break;;
|
||||||
|
[Nn]* ) exit;;
|
||||||
|
* ) echo "Please answer yes or no.";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
@@ -367,6 +367,7 @@ oraclesdata 17a841a919c284cea8a676f34e793da002e606f19a9258a3190bed12d5aaa3ff 034
|
|||||||
|
|
||||||
#define ORACLETXID "4895f631316a649e216153aee7a574bd281686265dc4e8d37597f72353facac3"
|
#define ORACLETXID "4895f631316a649e216153aee7a574bd281686265dc4e8d37597f72353facac3"
|
||||||
#define MYPUBKEY "02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92"
|
#define MYPUBKEY "02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92"
|
||||||
|
#define ACNAME "ORCL"
|
||||||
|
|
||||||
int32_t main(int32_t argc,char **argv)
|
int32_t main(int32_t argc,char **argv)
|
||||||
{
|
{
|
||||||
@@ -375,7 +376,7 @@ int32_t main(int32_t argc,char **argv)
|
|||||||
while ( 1 )
|
while ( 1 )
|
||||||
{
|
{
|
||||||
retstr = 0;
|
retstr = 0;
|
||||||
if ( (price= get_btcusd()) != 0 && (clijson= get_komodocli(&retstr,"AT5","oraclesinfo",ORACLETXID,"","")) != 0 )
|
if ( (price= get_btcusd()) != 0 && (clijson= get_komodocli(&retstr,ACNAME,"oraclesinfo",ORACLETXID,"","")) != 0 )
|
||||||
{
|
{
|
||||||
if ( (regjson= jarray(&n,clijson,"registered")) != 0 )
|
if ( (regjson= jarray(&n,clijson,"registered")) != 0 )
|
||||||
{
|
{
|
||||||
@@ -387,10 +388,10 @@ int32_t main(int32_t argc,char **argv)
|
|||||||
for (j=0; j<8; j++)
|
for (j=0; j<8; j++)
|
||||||
sprintf(&hexstr[j*2],"%02x",(uint8_t)((price >> (j*8)) & 0xff));
|
sprintf(&hexstr[j*2],"%02x",(uint8_t)((price >> (j*8)) & 0xff));
|
||||||
hexstr[16] = 0;
|
hexstr[16] = 0;
|
||||||
if ( (clijson2= get_komodocli(&retstr2,"AT5","oraclesdata",ORACLETXID,hexstr,"")) != 0 )
|
if ( (clijson2= get_komodocli(&retstr2,ACNAME,"oraclesdata",ORACLETXID,hexstr,"")) != 0 )
|
||||||
{
|
{
|
||||||
//printf("data.(%s)\n",jprint(clijson2,0));
|
//printf("data.(%s)\n",jprint(clijson2,0));
|
||||||
komodobroadcast("AT5",clijson2);
|
komodobroadcast(ACNAME,clijson2);
|
||||||
free_json(clijson2);
|
free_json(clijson2);
|
||||||
}
|
}
|
||||||
else if ( retstr2 != 0 )
|
else if ( retstr2 != 0 )
|
||||||
|
|||||||
@@ -41,6 +41,51 @@
|
|||||||
deposit addr can be 1 to MofN pubkeys
|
deposit addr can be 1 to MofN pubkeys
|
||||||
1:1 gateway with native coin
|
1:1 gateway with native coin
|
||||||
|
|
||||||
|
In order to create a new gateway it is necessary to follow some strict steps.
|
||||||
|
1. create a token with the max possible supply that will be issued
|
||||||
|
2. transfer 100% of them to the gateways CC's global pubkey's asset CC address. (yes it is a bit confusing)
|
||||||
|
3. create an oracle with the identical name, ie. KMD and format must start with Ihh (height, blockhash, merkleroot)
|
||||||
|
4. register a publisher and fund it with a subscribe. there will be a special client app that will automatically publish the merkleroots.
|
||||||
|
5. Now a gatewaysbind can bind an external coin to an asset, along with the oracle for the merkleroots
|
||||||
|
|
||||||
|
|
||||||
|
usage:
|
||||||
|
./c tokencreate KMD 1000000 KMD_equivalent_token_for_gatewaysCC
|
||||||
|
a7398a8748354dd0a3f8d07d70e65294928ecc3674674bb2d9483011ccaa9a7a
|
||||||
|
|
||||||
|
transfer to gateways pubkey: 03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40 RDMqGyREkP1Gwub1Nr5Ye8a325LGZsWBCb
|
||||||
|
./c tokentransfer a7398a8748354dd0a3f8d07d70e65294928ecc3674674bb2d9483011ccaa9a7a 03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40 100000000000000
|
||||||
|
2206fc39c0f384ca79819eb491ddbf889642cbfe4d0796bb6a8010ed53064a56
|
||||||
|
|
||||||
|
./c oraclescreate KMD blockheaders Ihh
|
||||||
|
1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808
|
||||||
|
|
||||||
|
./c oraclesregister 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 1000000
|
||||||
|
83b59eac238cbe54616ee13b2fdde85a48ec869295eb04051671a1727c9eb402
|
||||||
|
|
||||||
|
./c oraclessubscribe 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92 1000
|
||||||
|
f9499d8bb04ffb511fcec4838d72e642ec832558824a2ce5aed87f1f686f8102
|
||||||
|
|
||||||
|
./c gatewaysbind a7398a8748354dd0a3f8d07d70e65294928ecc3674674bb2d9483011ccaa9a7a 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 KMD 100000000000000 1 1 02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92
|
||||||
|
e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e
|
||||||
|
|
||||||
|
./c gatewaysinfo e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e
|
||||||
|
{
|
||||||
|
"result": "success",
|
||||||
|
"name": "Gateways",
|
||||||
|
"pubkey": "02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",
|
||||||
|
"coin": "KMD",
|
||||||
|
"oracletxid": "1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808",
|
||||||
|
"taddr": 0,
|
||||||
|
"prefix": 60,
|
||||||
|
"prefix2": 85,
|
||||||
|
"deposit": "",
|
||||||
|
"tokenid": "a7398a8748354dd0a3f8d07d70e65294928ecc3674674bb2d9483011ccaa9a7a",
|
||||||
|
"totalsupply": "1000000.00000000",
|
||||||
|
"remaining": "1000000.00000000",
|
||||||
|
"issued": "0.00000000"
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// start of consensus code
|
// start of consensus code
|
||||||
@@ -48,7 +93,7 @@
|
|||||||
CScript EncodeGatewaysBindOpRet(uint8_t funcid,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> pubkeys,uint8_t taddr,uint8_t prefix,uint8_t prefix2)
|
CScript EncodeGatewaysBindOpRet(uint8_t funcid,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector<CPubKey> pubkeys,uint8_t taddr,uint8_t prefix,uint8_t prefix2)
|
||||||
{
|
{
|
||||||
CScript opret; uint8_t evalcode = EVAL_GATEWAYS;
|
CScript opret; uint8_t evalcode = EVAL_GATEWAYS;
|
||||||
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << coin << prefix << prefix2 << taddr << tokenid << totalsupply << M << N << pubkeys);
|
opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << coin << prefix << prefix2 << taddr << tokenid << totalsupply << M << N << pubkeys << oracletxid);
|
||||||
return(opret);
|
return(opret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +122,7 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,st
|
|||||||
GetOpReturnData(scriptPubKey, vopret);
|
GetOpReturnData(scriptPubKey, vopret);
|
||||||
script = (uint8_t *)vopret.data();
|
script = (uint8_t *)vopret.data();
|
||||||
depositaddr[0] = 0;
|
depositaddr[0] = 0;
|
||||||
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> coin; ss >> prefix; ss >> prefix2; ss >> taddr; ss >> tokenid; ss >> totalsupply; ss >> M; ss >> N; ss >> pubkeys) != 0 )
|
if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> coin; ss >> prefix; ss >> prefix2; ss >> taddr; ss >> tokenid; ss >> totalsupply; ss >> M; ss >> N; ss >> pubkeys; ss >> oracletxid) != 0 )
|
||||||
{
|
{
|
||||||
if ( prefix == 60 )
|
if ( prefix == 60 )
|
||||||
{
|
{
|
||||||
@@ -214,11 +259,12 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP
|
|||||||
|
|
||||||
UniValue GatewaysInfo(uint256 bindtxid)
|
UniValue GatewaysInfo(uint256 bindtxid)
|
||||||
{
|
{
|
||||||
UniValue result(UniValue::VOBJ); std::string coin; char str[65],numstr[65],depositaddr[64]; uint8_t M,N; std::vector<CPubKey> pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CMutableTransaction mtx; CPubKey Gatewayspk; struct CCcontract_info *cp,C; int64_t totalsupply,remaining;
|
UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::string coin; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector<CPubKey> pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CMutableTransaction mtx; CPubKey Gatewayspk; struct CCcontract_info *cp,C; int32_t i; int64_t totalsupply,remaining;
|
||||||
result.push_back(Pair("result","success"));
|
result.push_back(Pair("result","success"));
|
||||||
result.push_back(Pair("name","Gateways"));
|
result.push_back(Pair("name","Gateways"));
|
||||||
cp = CCinit(&C,EVAL_GATEWAYS);
|
cp = CCinit(&C,EVAL_GATEWAYS);
|
||||||
Gatewayspk = GetUnspendable(cp,0);
|
Gatewayspk = GetUnspendable(cp,0);
|
||||||
|
_GetCCaddress(gatewaysassets,EVAL_ASSETS,Gatewayspk);
|
||||||
if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 )
|
if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 )
|
||||||
{
|
{
|
||||||
if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 0 )
|
if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 0 )
|
||||||
@@ -228,7 +274,10 @@ UniValue GatewaysInfo(uint256 bindtxid)
|
|||||||
{
|
{
|
||||||
result.push_back(Pair("M",M));
|
result.push_back(Pair("M",M));
|
||||||
result.push_back(Pair("N",N));
|
result.push_back(Pair("N",N));
|
||||||
}
|
for (i=0; i<N; i++)
|
||||||
|
a.push_back(pubkey33_str(str,(uint8_t *)&pubkeys[i]));
|
||||||
|
result.push_back(Pair("pubkeys",a));
|
||||||
|
} else result.push_back(Pair("pubkey",pubkey33_str(str,(uint8_t *)&pubkeys[0])));
|
||||||
result.push_back(Pair("coin",coin));
|
result.push_back(Pair("coin",coin));
|
||||||
result.push_back(Pair("oracletxid",uint256_str(str,oracletxid)));
|
result.push_back(Pair("oracletxid",uint256_str(str,oracletxid)));
|
||||||
result.push_back(Pair("taddr",taddr));
|
result.push_back(Pair("taddr",taddr));
|
||||||
@@ -238,7 +287,7 @@ UniValue GatewaysInfo(uint256 bindtxid)
|
|||||||
result.push_back(Pair("tokenid",uint256_str(str,tokenid)));
|
result.push_back(Pair("tokenid",uint256_str(str,tokenid)));
|
||||||
sprintf(numstr,"%.8f",(double)totalsupply/COIN);
|
sprintf(numstr,"%.8f",(double)totalsupply/COIN);
|
||||||
result.push_back(Pair("totalsupply",numstr));
|
result.push_back(Pair("totalsupply",numstr));
|
||||||
remaining = CCaddress_balance(depositaddr);
|
remaining = CCaddress_balance(gatewaysassets);
|
||||||
sprintf(numstr,"%.8f",(double)remaining/COIN);
|
sprintf(numstr,"%.8f",(double)remaining/COIN);
|
||||||
result.push_back(Pair("remaining",numstr));
|
result.push_back(Pair("remaining",numstr));
|
||||||
sprintf(numstr,"%.8f",(double)(totalsupply - remaining)/COIN);
|
sprintf(numstr,"%.8f",(double)(totalsupply - remaining)/COIN);
|
||||||
|
|||||||
@@ -5427,12 +5427,11 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp)
|
|||||||
N = atoi((char *)params[5].get_str().c_str());
|
N = atoi((char *)params[5].get_str().c_str());
|
||||||
if ( M > N || N == 0 || N > 15 || totalsupply < COIN/100 || tokenid == zeroid )
|
if ( M > N || N == 0 || N > 15 || totalsupply < COIN/100 || tokenid == zeroid )
|
||||||
throw runtime_error("illegal M or N > 15 or tokensupply or invalid tokenid\n");
|
throw runtime_error("illegal M or N > 15 or tokensupply or invalid tokenid\n");
|
||||||
pubkeys.resize(N);
|
|
||||||
for (i=0; i<N; i++)
|
for (i=0; i<N; i++)
|
||||||
{
|
{
|
||||||
if ( params.size() < 5+i+1 )
|
if ( params.size() < 6+i+1 )
|
||||||
throw runtime_error("not enough parameters for N pubkeys\n");
|
throw runtime_error("not enough parameters for N pubkeys\n");
|
||||||
pubkey = ParseHex(params[5+i].get_str().c_str());
|
pubkey = ParseHex(params[6+i].get_str().c_str());
|
||||||
pubkeys.push_back(pubkey2pk(pubkey));
|
pubkeys.push_back(pubkey2pk(pubkey));
|
||||||
}
|
}
|
||||||
hex = GatewaysBind(0,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys);
|
hex = GatewaysBind(0,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys);
|
||||||
|
|||||||
Reference in New Issue
Block a user