From 646eb9755021af2d382ece4f708237ecd4af91d5 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 7 Sep 2018 19:42:00 +0700 Subject: [PATCH 1/8] added dapp setup script --- src/cc/dapps/oracle_dapp.sh | 24 ++++++++++++++++++++++++ src/cc/dapps/oraclefeed.c | 7 ++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100755 src/cc/dapps/oracle_dapp.sh diff --git a/src/cc/dapps/oracle_dapp.sh b/src/cc/dapps/oracle_dapp.sh new file mode 100755 index 000000000..ff10f2c3f --- /dev/null +++ b/src/cc/dapps/oracle_dapp.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# 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 +# SET AC +read -p "Enter AC name you use : " acname +sed -i "/#define ACNAME */c\#define ACNAME \"$acname\"" 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 diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index e2a7c6830..f32ef3f73 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -392,6 +392,7 @@ oraclesdata 17a841a919c284cea8a676f34e793da002e606f19a9258a3190bed12d5aaa3ff 034 #define ORACLETXID "4895f631316a649e216153aee7a574bd281686265dc4e8d37597f72353facac3" #define MYPUBKEY "02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92" +#define ACNAME "ORCL" int32_t main(int32_t argc,char **argv) { @@ -400,7 +401,7 @@ int32_t main(int32_t argc,char **argv) while ( 1 ) { 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 ) { @@ -412,10 +413,10 @@ int32_t main(int32_t argc,char **argv) for (j=0; j<8; j++) sprintf(&hexstr[j*2],"%02x",(uint8_t)((price >> (j*8)) & 0xff)); 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)); - komodobroadcast("AT5",clijson2); + komodobroadcast(ACNAME,clijson2); free_json(clijson2); } else if ( retstr2 != 0 ) From 3d58cd169eb844189600624ada981fc81d52398b Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 7 Sep 2018 19:47:29 +0700 Subject: [PATCH 2/8] Update oracle_dapp.sh More clever is to ask for acname first --- src/cc/dapps/oracle_dapp.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oracle_dapp.sh b/src/cc/dapps/oracle_dapp.sh index ff10f2c3f..f6efd6a2b 100755 --- a/src/cc/dapps/oracle_dapp.sh +++ b/src/cc/dapps/oracle_dapp.sh @@ -1,14 +1,14 @@ #!/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 -# SET AC -read -p "Enter AC name you use : " acname -sed -i "/#define ACNAME */c\#define ACNAME \"$acname\"" oraclefeed.c # COMPILATION echo "Great, compiling !" gcc oraclefeed.c -lm -o oracle_dapp From 77fad4320d8f16e3fa5158910a8241dac51efbe1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 10 Sep 2018 02:35:54 -1100 Subject: [PATCH 3/8] Test --- src/cc/gateways.cpp | 19 +++++++++++++++++++ src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index d6efa150a..c91cc4763 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -41,6 +41,25 @@ deposit addr can be 1 to MofN pubkeys 1:1 gateway with native coin + 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 + */ // start of consensus code diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 01180b69d..bd3e5871f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5430,9 +5430,9 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp) pubkeys.resize(N); for (i=0; i Date: Mon, 10 Sep 2018 02:40:35 -1100 Subject: [PATCH 4/8] Test --- src/wallet/rpcwallet.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bd3e5871f..83807da23 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5427,7 +5427,6 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp) N = atoi((char *)params[5].get_str().c_str()); 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"); - pubkeys.resize(N); for (i=0; i Date: Mon, 10 Sep 2018 02:53:02 -1100 Subject: [PATCH 5/8] Test --- src/cc/gateways.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index c91cc4763..d575c5559 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -41,6 +41,14 @@ deposit addr can be 1 to MofN pubkeys 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 @@ -59,6 +67,8 @@ f9499d8bb04ffb511fcec4838d72e642ec832558824a2ce5aed87f1f686f8102 ./c gatewaysbind a7398a8748354dd0a3f8d07d70e65294928ecc3674674bb2d9483011ccaa9a7a 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 KMD 100000000000000 1 1 02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92 + abc09a431d6c720f56fd324f1d2ab23d42dc34fd9e0fa2fad40d6eddb903f9a4 + */ @@ -67,7 +77,7 @@ CScript EncodeGatewaysBindOpRet(uint8_t funcid,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys,uint8_t taddr,uint8_t prefix,uint8_t prefix2) { 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); } @@ -96,7 +106,7 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,st GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); 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 ) { @@ -233,11 +243,12 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP UniValue GatewaysInfo(uint256 bindtxid) { - UniValue result(UniValue::VOBJ); std::string coin; char str[65],numstr[65],depositaddr[64]; uint8_t M,N; std::vector 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 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; result.push_back(Pair("result","success")); result.push_back(Pair("name","Gateways")); cp = CCinit(&C,EVAL_GATEWAYS); Gatewayspk = GetUnspendable(cp,0); + _GetCCaddress(gatewaysassets,EVAL_ASSETS,gatewayspk); 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 ) @@ -247,7 +258,10 @@ UniValue GatewaysInfo(uint256 bindtxid) { result.push_back(Pair("M",M)); result.push_back(Pair("N",N)); - } + for (i=0; i Date: Mon, 10 Sep 2018 02:54:29 -1100 Subject: [PATCH 6/8] Test --- src/cc/gateways.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index d575c5559..3733d904f 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -243,12 +243,12 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP UniValue GatewaysInfo(uint256 bindtxid) { - 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 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 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("name","Gateways")); cp = CCinit(&C,EVAL_GATEWAYS); Gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(gatewaysassets,EVAL_ASSETS,gatewayspk); + _GetCCaddress(gatewaysassets,EVAL_ASSETS,Gatewayspk); 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 ) From 434e600cd406cfec0676361daae8b76de5e35db6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 10 Sep 2018 02:56:42 -1100 Subject: [PATCH 7/8] (uint8_t *)& --- src/cc/gateways.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 3733d904f..23d0ed948 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -259,9 +259,9 @@ UniValue GatewaysInfo(uint256 bindtxid) result.push_back(Pair("M",M)); result.push_back(Pair("N",N)); for (i=0; i Date: Mon, 10 Sep 2018 03:00:08 -1100 Subject: [PATCH 8/8] gatewaysCC up to bind debugged --- src/cc/gateways.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 23d0ed948..b582e2578 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -67,9 +67,25 @@ f9499d8bb04ffb511fcec4838d72e642ec832558824a2ce5aed87f1f686f8102 ./c gatewaysbind a7398a8748354dd0a3f8d07d70e65294928ecc3674674bb2d9483011ccaa9a7a 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 KMD 100000000000000 1 1 02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92 - abc09a431d6c720f56fd324f1d2ab23d42dc34fd9e0fa2fad40d6eddb903f9a4 - + 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