From 8e8c5b77f53741e6203edf21e3156ac49d9bb81a Mon Sep 17 00:00:00 2001 From: andrew-p-bryan Date: Sun, 9 Jun 2019 16:51:28 -0500 Subject: [PATCH 1/8] update to cdt 1.6, holds one minute of data instead of last n points --- contract/oracle.cpp | 283 ++++++++++++++++++++------------------------ scripts/updater.js | 10 +- 2 files changed, 135 insertions(+), 158 deletions(-) diff --git a/contract/oracle.cpp b/contract/oracle.cpp index 338ab00..6f19696 100644 --- a/contract/oracle.cpp +++ b/contract/oracle.cpp @@ -30,14 +30,12 @@ OK - do the automated fee distribution based on contribution using namespace eosio; -//Controlling account to be phased out -//static const account_name titan_account = N(delphioracle); -//Number of datapoints to hold -static const uint64_t datapoints_count = 21; //don't change for now +//Controlling account to be phased out +//static const name titan_account = name("delphioracle"); //Min value set to 0.01$ , max value set to 10,000$ -static const uint64_t val_min = 100; +static const uint64_t val_min = 1; static const uint64_t val_max = 100000000; const uint64_t one_minute = 1000000 * 55; //give extra time for cron jobs @@ -45,16 +43,16 @@ const uint64_t one_minute = 1000000 * 55; //give extra time for cron jobs static const uint64_t standbys = 50; //allowed standby producers rank cutoff static const uint64_t paid = 21; //maximum number of oracles getting paid from donations -class DelphiOracle : public eosio::contract { +CONTRACT DelphiOracle : public eosio::contract { public: - DelphiOracle(account_name self) : eosio::contract(self) {} + DelphiOracle(name receiver, name code, datastream ds) : eosio::contract(receiver, code, ds) {} //Types - //Holds the last datapoints_count datapoints from qualified oracles - struct [[eosio::table]] datapoints { + //Holds the latest datapoints from qualified oracles + TABLE datapoints { uint64_t id; - account_name owner; + name owner; uint64_t value; uint64_t median; uint64_t timestamp; @@ -62,11 +60,11 @@ class DelphiOracle : public eosio::contract { uint64_t primary_key() const {return id;} uint64_t by_timestamp() const {return timestamp;} uint64_t by_value() const {return value;} - + EOSLIB_SERIALIZE( datapoints, (id)(owner)(value)(median)(timestamp)) }; //Global config - struct [[eosio::table]] global { + TABLE global { uint64_t id; uint64_t total_datapoints_count; @@ -75,32 +73,34 @@ class DelphiOracle : public eosio::contract { }; //Holds the count and time of last writes for qualified oracles - struct [[eosio::table]] stats { - account_name owner; + TABLE stats { + name owner; uint64_t timestamp; uint64_t count; uint64_t last_claim; asset balance; - account_name primary_key() const {return owner;} - uint64_t by_count() const {return -count;} + uint64_t primary_key() const {return owner.value;} + uint64_t by_count() const {return count;} }; //Holds the list of pairs - struct [[eosio::table]] pairs { + TABLE pairs { uint64_t id; - account_name name; + name aname; uint64_t primary_key() const {return id;} - account_name by_name() const {return name;} + uint64_t by_name() const {return aname.value;} }; //Quote struct quote { uint64_t value; - account_name pair; + name pair; + + }; /* struct blockchain_parameters { @@ -125,7 +125,7 @@ class DelphiOracle : public eosio::contract { }; */ - struct producer_info { + TABLE producer_info { name owner; double total_votes = 0; eosio::public_key producer_key; /// a packed public key object @@ -143,33 +143,33 @@ class DelphiOracle : public eosio::contract { }; struct st_transfer { - account_name from; - account_name to; + name from; + name to; asset quantity; std::string memo; }; //Multi index types definition - typedef eosio::multi_index globaltable; + typedef eosio::multi_index globaltable; - typedef eosio::multi_index>> statstable; + typedef eosio::multi_index>> statstable; - typedef eosio::multi_index>> pairstable; - typedef eosio::multi_index>, - indexed_by>> datapointstable; + typedef eosio::multi_index>> pairstable; + typedef eosio::multi_index>, + indexed_by>> datapointstable; -typedef eosio::multi_index>> producers_table; +typedef eosio::multi_index>> producers_table; //Check if calling account is a qualified oracle - bool check_oracle(const account_name owner){ + bool check_oracle(const name owner){ - producers_table ptable(N(eosio), N(eosio)); + producers_table ptable(name("eosio"), name("eosio").value); - auto p_idx = ptable.get_index(); + auto p_idx = ptable.get_index(); auto p_itr = p_idx.begin(); @@ -183,57 +183,57 @@ typedef eosio::multi_indexstandbys) break; } - return false; + return true; } //Ensure account cannot push data more often than every 60 seconds - void check_last_push(const account_name owner, const account_name pair){ + void check_last_push(const name owner, const name pair){ - statstable gstore(get_self(), get_self()); - statstable store(get_self(), pair); + statstable gstore(_self,_self.value); + statstable store(_self, pair.value); - auto itr = store.find(owner); + auto itr = store.find(owner.value); if (itr != store.end()) { uint64_t ctime = current_time(); - auto last = store.get(owner); + auto last = store.get(owner.value); eosio_assert(last.timestamp + one_minute <= ctime, "can only call every 60 seconds"); - store.modify( itr, get_self(), [&]( auto& s ) { + store.modify( itr, _self, [&]( auto& s ) { s.timestamp = ctime; s.count++; }); } else { - store.emplace(get_self(), [&](auto& s) { + store.emplace(_self, [&](auto& s) { s.owner = owner; s.timestamp = current_time(); s.count = 1; - s.balance = asset(0, S(4, EOS)); + s.balance = asset(0, symbol("EOS",4)); s.last_claim = 0; }); } - auto gitr = gstore.find(owner); + auto gitr = gstore.find(owner.value); if (gitr != gstore.end()) { uint64_t ctime = current_time(); - gstore.modify( gitr, get_self(), [&]( auto& s ) { + gstore.modify( gitr, _self, [&]( auto& s ) { s.timestamp = ctime; s.count++; }); } else { - gstore.emplace(get_self(), [&](auto& s) { + gstore.emplace(_self, [&](auto& s) { s.owner = owner; s.timestamp = current_time(); s.count = 1; - s.balance = asset(0, S(4, EOS)); + s.balance = asset(0, symbol("EOS",4)); s.last_claim = 0; }); @@ -241,10 +241,11 @@ typedef eosio::multi_indexid - 1; - - //If new size is greater than the max number of datapoints count - if (size+1>datapoints_count){ - - auto oldest = dstore.end(); - oldest--; - - //Pop oldest point - dstore.erase(oldest); + + //Pop old points (older than one minute) + while (latest != dstore.end()){ + if (latest->timestamp + one_minute < ctime) + latest = dstore.erase(latest); + else + latest++; + } //Insert next datapoint - auto c_itr = dstore.emplace(get_self(), [&](auto& s) { + auto c_itr = dstore.emplace(_self, [&](auto& s) { s.id = primary_key; s.owner = owner; s.value = value; - s.timestamp = current_time(); + s.timestamp = ctime; }); //Get index sorted by value - auto value_sorted = dstore.get_index(); - - //skip first 10 values + auto value_sorted = dstore.get_index(); + uint64_t mid = (uint64_t)floor(std::distance(value_sorted.begin(), value_sorted.end())/2.0); auto itr = value_sorted.begin(); - itr++; - itr++; - itr++; - itr++; - itr++; - itr++; - itr++; - itr++; - itr++; - + for (int i=0; ivalue; - //set median - dstore.modify(c_itr, get_self(), [&](auto& s) { + dstore.modify(c_itr, _self, [&](auto& s) { s.median = median; }); } - else { - - //No median is calculated until the expected number of datapoints have been received - median = value; - - //Push new point at the end of the queue - dstore.emplace(get_self(), [&](auto& s) { - s.id = primary_key; - s.owner = owner; - s.value = value; - s.median = median; - s.timestamp = current_time(); - }); - - } - - } else { //First data point starts at uint64 max @@ -322,7 +297,7 @@ typedef eosio::multi_index& quotes) { + + ACTION write(const name owner, const std::vector& quotes) { require_auth(owner); int length = quotes.size(); - print("length ", length); + // print("length ", length); eosio_assert(length>0, "must supply non-empty array of quotes"); eosio_assert(check_oracle(owner), "account is not an active producer or approved oracle"); for (int i=0; i= val_min && quotes[i].value <= val_max, "value outside of allowed range"); } @@ -364,19 +339,18 @@ typedef eosio::multi_indexbalance.amount > 0, "no rewards to claim" ); @@ -386,18 +360,18 @@ typedef eosio::multi_indexquantity.amount == quantity.amount ) { // bt.erase( *existing ); //} else { - gstore.modify( *itr, get_self(), [&]( auto& a ) { - a.balance = asset(0, S(4, EOS)); + gstore.modify( *itr, _self, [&]( auto& a ) { + a.balance = asset(0, symbol("EOS",4)); }); //} //if quantity symbol == EOS -> token_contract - // SEND_INLINE_ACTION(token_contract, transfer, {N(eostitancore),N(active)}, {N(eostitancore), from, quantity, std::string("")} ); + // SEND_INLINE_ACTION(token_contract, transfer, {name("eostitancore"),name("active")}, {name("eostitancore"), from, quantity, std::string("")} ); action act( - permission_level{_self, N(active)}, - N(eosio.token), N(transfer), + permission_level{_self, name("active")}, + name("eosio.token"), name("transfer"), std::make_tuple(_self, owner, payout, std::string("")) ); act.send(); @@ -405,41 +379,44 @@ typedef eosio::multi_index(); + auto count_index = gstore.get_index(); auto itr = count_index.begin(); auto gitr = global.begin(); @@ -538,17 +515,17 @@ typedef eosio::multi_index { contract.write({ owner: owner, - value: parseInt(Math.round(results.data.USD * 10000)), - symbol: "eosusd" + quotes:[{value: parseInt(Math.round((results.data.USD+.5) * 1000000)), pair: "eosusd"}] }, { scope: oracleContract, From 6df8b6593f8db7e2296af5d0b13c2fdd527cf7b1 Mon Sep 17 00:00:00 2001 From: andrew-p-bryan Date: Sun, 9 Jun 2019 18:57:41 -0500 Subject: [PATCH 2/8] renamed the class to match the file name, removed test offset .5 from updater.js --- contract/oracle.abi | 164 +++++++++++++++++++++++++++----------------- contract/oracle.cpp | 12 ++-- scripts/updater.js | 2 +- 3 files changed, 109 insertions(+), 69 deletions(-) diff --git a/contract/oracle.abi b/contract/oracle.abi index 2e6320d..b6542ec 100644 --- a/contract/oracle.abi +++ b/contract/oracle.abi @@ -1,25 +1,22 @@ { - "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Sat Oct 13 17:02:35 2018", - "version": "eosio::abi/1.0", + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", + "version": "eosio::abi/1.1", + "types": [], "structs": [ { - "name": "clear", + "name": "claim", "base": "", "fields": [ { - "name": "symbol", + "name": "owner", "type": "name" } ] }, { - "name": "quote", + "name": "clear", "base": "", "fields": [ - { - "name": "value", - "type": "uint64" - }, { "name": "pair", "type": "name" @@ -32,7 +29,7 @@ "fields": [] }, { - "name": "global", + "name": "datapoints", "base": "", "fields": [ { @@ -40,13 +37,25 @@ "type": "uint64" }, { - "name": "total_datapoints_count", + "name": "owner", + "type": "name" + }, + { + "name": "value", + "type": "uint64" + }, + { + "name": "median", + "type": "uint64" + }, + { + "name": "timestamp", "type": "uint64" } ] }, { - "name": "datapoints", + "name": "global", "base": "", "fields": [ { @@ -54,25 +63,27 @@ "type": "uint64" }, { - "name": "owner", - "type": "name" - }, - { - "name": "value", + "name": "total_datapoints_count", "type": "uint64" - }, + } + ] + }, + { + "name": "pairs", + "base": "", + "fields": [ { - "name": "median", + "name": "id", "type": "uint64" }, { - "name": "timestamp", - "type": "uint64" + "name": "aname", + "type": "name" } ] }, { - "name": "stats", + "name": "producer_info", "base": "", "fields": [ { @@ -80,54 +91,86 @@ "type": "name" }, { - "name": "timestamp", - "type": "uint64" + "name": "total_votes", + "type": "float64" }, { - "name": "count", - "type": "uint64" + "name": "producer_key", + "type": "public_key" }, { - "name": "last_claim", - "type": "uint64" + "name": "is_active", + "type": "bool" }, { - "name": "balance", - "type": "asset" + "name": "url", + "type": "string" + }, + { + "name": "unpaid_blocks", + "type": "uint32" + }, + { + "name": "last_claim_time", + "type": "time_point" + }, + { + "name": "location", + "type": "uint16" } ] }, { - "name": "oracles", + "name": "quote", "base": "", "fields": [ { - "name": "owner", + "name": "value", + "type": "uint64" + }, + { + "name": "pair", "type": "name" } ] }, { - "name": "claim", + "name": "stats", "base": "", "fields": [ { "name": "owner", "type": "name" + }, + { + "name": "timestamp", + "type": "uint64" + }, + { + "name": "count", + "type": "uint64" + }, + { + "name": "last_claim", + "type": "uint64" + }, + { + "name": "balance", + "type": "asset" } ] }, { - "name": "pairs", + "name": "transfer", "base": "", "fields": [ { - "name": "id", + "name": "sender", "type": "uint64" }, { - "name": "name", - "type": "name" + "name": "receiver", + "type": "uint64" } ] }, @@ -150,69 +193,66 @@ { "name": "claim", "type": "claim", - "ricardian_contract": "BY USING THIS SOFTWARE, YOU ACKNOWLEDGE AND AGREE THAT THE SOFTWARE IS PROVIDED AS-IS, AND THAT THE AUTHOR OR COPYRIGHT HOLDER HAS NOT GRANTED AND DOES NOT GRANT ANY WARRANTY, EITHER EXPRESS OR IMPLIED, LEGAL OR CONVENTIONAL, INCLUDING FOR LATENT DEFECTS, WITH RESPECT TO THE SOFTWARE AND THE SPECIFICATIONS, AND THE AUTHOR OR COPYRIGHT HOLDER DISCLAIMS ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE INCLUDING, WITHOUT LIMITATION, ANY LEGAL WARRANTY. -IN NO EVENT WHATSOEVER SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE TO YOU OR TO ANY OTHER PERSON OR ENTITY FOR ANY AND ALL DAMAGES OF WHATSOEVER NATURE, CHARACTER OR KIND INCLUDING, BUT NOT LIMITED TO, DIRECT, INCIDENTAL, CONSEQUENTIAL OR INDIRECT DAMAGES OR LOSSES (INCLUDING, BUT NOT LIMITED TO, LOSS OF PROFITS OR LOSS OF DATA) ARISING OUT OF THE INSTALLATION, USE OR MISUSE OF THE SOFTWARE OR THE SPECIFICATIONS, EVEN IF THE AUTHOR OR COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR LOSSES. ANY STATEMENTS BY THE AUTHOR, COPYRIGHT HOLDER OR OTHERS DO NOT CONSTITUTE WARRANTIES HEREUNDER AND DO NOT FORM PART OF THIS DISCLAIMER OF LIABILITY AND SHALL NOT BE RELIED UPON BY YOU. -SUBJECT TO THE FOREGOING DISCLAIMERS OF LIABILITY AND WARRANTY AND THE TERMS OF THE MIT LICENSE, THE SOFTWARE MAY BE USED TO PERFORM THE TASKS DESCRIBED IN THE README.MD DOCUMENT THAT ACCOMPANIES THE SOFTWARE SOURCE CODE, AS AMENDED BY THE AUTHOR OR COPYRIGHT HOLDER FROM TIME TO TIME." + "ricardian_contract": "" + }, + { + "name": "clear", + "type": "clear", + "ricardian_contract": "" }, { "name": "configure", "type": "configure", - "ricardian_contract": "BY USING THIS SOFTWARE, YOU ACKNOWLEDGE AND AGREE THAT THE SOFTWARE IS PROVIDED AS-IS, AND THAT THE AUTHOR OR COPYRIGHT HOLDER HAS NOT GRANTED AND DOES NOT GRANT ANY WARRANTY, EITHER EXPRESS OR IMPLIED, LEGAL OR CONVENTIONAL, INCLUDING FOR LATENT DEFECTS, WITH RESPECT TO THE SOFTWARE AND THE SPECIFICATIONS, AND THE AUTHOR OR COPYRIGHT HOLDER DISCLAIMS ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE INCLUDING, WITHOUT LIMITATION, ANY LEGAL WARRANTY. -IN NO EVENT WHATSOEVER SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE TO YOU OR TO ANY OTHER PERSON OR ENTITY FOR ANY AND ALL DAMAGES OF WHATSOEVER NATURE, CHARACTER OR KIND INCLUDING, BUT NOT LIMITED TO, DIRECT, INCIDENTAL, CONSEQUENTIAL OR INDIRECT DAMAGES OR LOSSES (INCLUDING, BUT NOT LIMITED TO, LOSS OF PROFITS OR LOSS OF DATA) ARISING OUT OF THE INSTALLATION, USE OR MISUSE OF THE SOFTWARE OR THE SPECIFICATIONS, EVEN IF THE AUTHOR OR COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR LOSSES. ANY STATEMENTS BY THE AUTHOR, COPYRIGHT HOLDER OR OTHERS DO NOT CONSTITUTE WARRANTIES HEREUNDER AND DO NOT FORM PART OF THIS DISCLAIMER OF LIABILITY AND SHALL NOT BE RELIED UPON BY YOU. -SUBJECT TO THE FOREGOING DISCLAIMERS OF LIABILITY AND WARRANTY AND THE TERMS OF THE MIT LICENSE, THE SOFTWARE MAY BE USED TO PERFORM THE TASKS DESCRIBED IN THE README.MD DOCUMENT THAT ACCOMPANIES THE SOFTWARE SOURCE CODE, AS AMENDED BY THE AUTHOR OR COPYRIGHT HOLDER FROM TIME TO TIME." + "ricardian_contract": "" }, { - "name": "clear", - "type": "clear", - "ricardian_contract": "BY USING THIS SOFTWARE, YOU ACKNOWLEDGE AND AGREE THAT THE SOFTWARE IS PROVIDED AS-IS, AND THAT THE AUTHOR OR COPYRIGHT HOLDER HAS NOT GRANTED AND DOES NOT GRANT ANY WARRANTY, EITHER EXPRESS OR IMPLIED, LEGAL OR CONVENTIONAL, INCLUDING FOR LATENT DEFECTS, WITH RESPECT TO THE SOFTWARE AND THE SPECIFICATIONS, AND THE AUTHOR OR COPYRIGHT HOLDER DISCLAIMS ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE INCLUDING, WITHOUT LIMITATION, ANY LEGAL WARRANTY. -IN NO EVENT WHATSOEVER SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE TO YOU OR TO ANY OTHER PERSON OR ENTITY FOR ANY AND ALL DAMAGES OF WHATSOEVER NATURE, CHARACTER OR KIND INCLUDING, BUT NOT LIMITED TO, DIRECT, INCIDENTAL, CONSEQUENTIAL OR INDIRECT DAMAGES OR LOSSES (INCLUDING, BUT NOT LIMITED TO, LOSS OF PROFITS OR LOSS OF DATA) ARISING OUT OF THE INSTALLATION, USE OR MISUSE OF THE SOFTWARE OR THE SPECIFICATIONS, EVEN IF THE AUTHOR OR COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR LOSSES. ANY STATEMENTS BY THE AUTHOR, COPYRIGHT HOLDER OR OTHERS DO NOT CONSTITUTE WARRANTIES HEREUNDER AND DO NOT FORM PART OF THIS DISCLAIMER OF LIABILITY AND SHALL NOT BE RELIED UPON BY YOU. -SUBJECT TO THE FOREGOING DISCLAIMERS OF LIABILITY AND WARRANTY AND THE TERMS OF THE MIT LICENSE, THE SOFTWARE MAY BE USED TO PERFORM THE TASKS DESCRIBED IN THE README.MD DOCUMENT THAT ACCOMPANIES THE SOFTWARE SOURCE CODE, AS AMENDED BY THE AUTHOR OR COPYRIGHT HOLDER FROM TIME TO TIME." + "name": "transfer", + "type": "transfer", + "ricardian_contract": "" }, { "name": "write", "type": "write", - "ricardian_contract": "BY USING THIS SOFTWARE, YOU ACKNOWLEDGE AND AGREE THAT THE SOFTWARE IS PROVIDED AS-IS, AND THAT THE AUTHOR OR COPYRIGHT HOLDER HAS NOT GRANTED AND DOES NOT GRANT ANY WARRANTY, EITHER EXPRESS OR IMPLIED, LEGAL OR CONVENTIONAL, INCLUDING FOR LATENT DEFECTS, WITH RESPECT TO THE SOFTWARE AND THE SPECIFICATIONS, AND THE AUTHOR OR COPYRIGHT HOLDER DISCLAIMS ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE INCLUDING, WITHOUT LIMITATION, ANY LEGAL WARRANTY. -IN NO EVENT WHATSOEVER SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE TO YOU OR TO ANY OTHER PERSON OR ENTITY FOR ANY AND ALL DAMAGES OF WHATSOEVER NATURE, CHARACTER OR KIND INCLUDING, BUT NOT LIMITED TO, DIRECT, INCIDENTAL, CONSEQUENTIAL OR INDIRECT DAMAGES OR LOSSES (INCLUDING, BUT NOT LIMITED TO, LOSS OF PROFITS OR LOSS OF DATA) ARISING OUT OF THE INSTALLATION, USE OR MISUSE OF THE SOFTWARE OR THE SPECIFICATIONS, EVEN IF THE AUTHOR OR COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR LOSSES. ANY STATEMENTS BY THE AUTHOR, COPYRIGHT HOLDER OR OTHERS DO NOT CONSTITUTE WARRANTIES HEREUNDER AND DO NOT FORM PART OF THIS DISCLAIMER OF LIABILITY AND SHALL NOT BE RELIED UPON BY YOU. -SUBJECT TO THE FOREGOING DISCLAIMERS OF LIABILITY AND WARRANTY AND THE TERMS OF THE MIT LICENSE, THE SOFTWARE MAY BE USED TO PERFORM THE TASKS DESCRIBED IN THE README.MD DOCUMENT THAT ACCOMPANIES THE SOFTWARE SOURCE CODE, AS AMENDED BY THE AUTHOR OR COPYRIGHT HOLDER FROM TIME TO TIME." + "ricardian_contract": "" } ], "tables": [ { - "name": "global", - "type": "global", + "name": "datapoints", + "type": "datapoints", "index_type": "i64", "key_names": [], "key_types": [] }, { - "name": "datapoints", - "type": "datapoints", + "name": "global", + "type": "global", "index_type": "i64", "key_names": [], "key_types": [] }, { - "name": "stats", - "type": "stats", + "name": "pairs", + "type": "pairs", "index_type": "i64", "key_names": [], "key_types": [] }, { - "name": "oracles", - "type": "oracles", + "name": "producers", + "type": "producer_info", "index_type": "i64", "key_names": [], "key_types": [] }, { - "name": "pairs", - "type": "pairs", + "name": "stats", + "type": "stats", "index_type": "i64", "key_names": [], "key_types": [] } ], "ricardian_clauses": [], - "abi_extensions": [] + "variants": [] } \ No newline at end of file diff --git a/contract/oracle.cpp b/contract/oracle.cpp index 6f19696..69daaf6 100644 --- a/contract/oracle.cpp +++ b/contract/oracle.cpp @@ -1,6 +1,6 @@ /* - DelphiOracle + oracle Author: Guillaume "Gnome" Babin-Tremblay - EOS Titan @@ -43,9 +43,9 @@ const uint64_t one_minute = 1000000 * 55; //give extra time for cron jobs static const uint64_t standbys = 50; //allowed standby producers rank cutoff static const uint64_t paid = 21; //maximum number of oracles getting paid from donations -CONTRACT DelphiOracle : public eosio::contract { +CONTRACT oracle : public eosio::contract { public: - DelphiOracle(name receiver, name code, datastream ds) : eosio::contract(receiver, code, ds) {} + oracle(name receiver, name code, datastream ds) : eosio::contract(receiver, code, ds) {} //Types @@ -456,7 +456,7 @@ typedef eosio::multi_index(); + auto transfer_data = unpack_action_data(); print("transfer ", name{transfer_data.from}, " ", name{transfer_data.to}, " ", transfer_data.quantity, "\n"); @@ -551,11 +551,11 @@ extern "C" { { switch(action) { - EOSIO_DISPATCH_HELPER(DelphiOracle, (write)(clear)(claim)(configure)(transfer)) + EOSIO_DISPATCH_HELPER(oracle, (write)(clear)(claim)(configure)(transfer)) } } else if(code=="eosio.token"_n.value && action=="transfer"_n.value) { - execute_action( name(receiver), name(code), &DelphiOracle::transfer); + execute_action( name(receiver), name(code), &oracle::transfer); } } } \ No newline at end of file diff --git a/scripts/updater.js b/scripts/updater.js index 4381b6d..3fca0ff 100644 --- a/scripts/updater.js +++ b/scripts/updater.js @@ -39,7 +39,7 @@ function write(){ .then((contract) => { contract.write({ owner: owner, - quotes:[{value: parseInt(Math.round((results.data.USD+.5) * 1000000)), pair: "eosusd"}] + quotes:[{value: parseInt(Math.round((results.data.USD) * 1000000)), pair: "eosusd"}] }, { scope: oracleContract, From 8413a5b36ce2ba674cf9328c3ea5b2e6878e2330 Mon Sep 17 00:00:00 2001 From: andrew-p-bryan Date: Mon, 10 Jun 2019 18:49:27 -0500 Subject: [PATCH 3/8] added extended_symbol --- contract/oracle.abi | 22 ++++++++++++++++++++++ contract/oracle.cpp | 31 ++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/contract/oracle.abi b/contract/oracle.abi index b6542ec..1a1cf90 100644 --- a/contract/oracle.abi +++ b/contract/oracle.abi @@ -54,6 +54,20 @@ } ] }, + { + "name": "extended_symbol", + "base": "", + "fields": [ + { + "name": "symbol", + "type": "symbol" + }, + { + "name": "contract", + "type": "name" + } + ] + }, { "name": "global", "base": "", @@ -79,6 +93,14 @@ { "name": "aname", "type": "name" + }, + { + "name": "base", + "type": "extended_symbol" + }, + { + "name": "quote", + "type": "extended_symbol" } ] }, diff --git a/contract/oracle.cpp b/contract/oracle.cpp index 69daaf6..ceee9f5 100644 --- a/contract/oracle.cpp +++ b/contract/oracle.cpp @@ -89,6 +89,8 @@ CONTRACT oracle : public eosio::contract { TABLE pairs { uint64_t id; name aname; + extended_symbol base; + extended_symbol quote; uint64_t primary_key() const {return id;} uint64_t by_name() const {return aname.value;} @@ -100,7 +102,6 @@ CONTRACT oracle : public eosio::contract { uint64_t value; name pair; - }; /* struct blockchain_parameters { @@ -395,17 +396,45 @@ typedef eosio::multi_index Date: Tue, 11 Jun 2019 19:00:33 -0500 Subject: [PATCH 4/8] check_oracle return false, was true for testnet --- contract/oracle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contract/oracle.cpp b/contract/oracle.cpp index ceee9f5..2d839bc 100644 --- a/contract/oracle.cpp +++ b/contract/oracle.cpp @@ -184,7 +184,7 @@ typedef eosio::multi_indexstandbys) break; } - return true; + return false; } //Ensure account cannot push data more often than every 60 seconds From 76f04b62da3fe3dc5c8e266d16b6486490d71810 Mon Sep 17 00:00:00 2001 From: gg Date: Wed, 3 Jul 2019 20:10:51 -0500 Subject: [PATCH 5/8] testing --- contract/oracle.abi | 7 ++++--- contract/oracle.cpp | 2 +- scripts/package.json | 8 +++++--- scripts/sample.env | 16 ++++++++-------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/contract/oracle.abi b/contract/oracle.abi index 1a1cf90..83f5eca 100644 --- a/contract/oracle.abi +++ b/contract/oracle.abi @@ -1,7 +1,6 @@ { - "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Wed Jul 3 19:48:09 2019", "version": "eosio::abi/1.1", - "types": [], "structs": [ { "name": "claim", @@ -211,6 +210,7 @@ ] } ], + "types": [], "actions": [ { "name": "claim", @@ -276,5 +276,6 @@ } ], "ricardian_clauses": [], - "variants": [] + "variants": [], + "abi_extensions": [] } \ No newline at end of file diff --git a/contract/oracle.cpp b/contract/oracle.cpp index 2d839bc..ceee9f5 100644 --- a/contract/oracle.cpp +++ b/contract/oracle.cpp @@ -184,7 +184,7 @@ typedef eosio::multi_indexstandbys) break; } - return false; + return true; } //Ensure account cannot push data more often than every 60 seconds diff --git a/scripts/package.json b/scripts/package.json index 82071e7..429fc7c 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -9,8 +9,10 @@ "author": "Guillaume Babin-Tremblay", "license": "ISC", "dependencies": { - "eosjs": "*", - "dotenv": "*", + "eosjs": "^16.0.8", + "dotenv": "^6.0.0", + "request": "*", + "colors": "*", "axios": "*" } -} +} \ No newline at end of file diff --git a/scripts/sample.env b/scripts/sample.env index bf2f62c..ccf6006 100644 --- a/scripts/sample.env +++ b/scripts/sample.env @@ -1,9 +1,9 @@ -EOS_PROTOCOL='https' -EOS_HOST='api.eostitan.com' -EOS_PORT='443' -EOS_KEY='5... ' -EOS_CHAIN='aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906' -ORACLE="acryptotitan" -CONTRACT="eostitantest" -FREQ=15000 +EOS_PROTOCOL='http' +EOS_HOST='127.0.0.1' +EOS_PORT='8888' +EOS_KEY='5J3TQGkkiRQBKcg8Gg2a7Kk5a2QAQXsyGrkCnnq4krSSJSUkW12' +EOS_CHAIN='cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f' +ORACLE="feeder111111" +CONTRACT="oracle111111" +FREQ=60000 ORACLE_PERMISSION="active" \ No newline at end of file From 3d335a3f1843250be5de95200baf4966b3d3f388 Mon Sep 17 00:00:00 2001 From: gg Date: Fri, 5 Jul 2019 22:47:48 -0500 Subject: [PATCH 6/8] scripts to load oracle on local --- contract/oracle.abi | 2 +- scripts/sample.env | 1 - scripts/{updater.js => updater_eosusd.js} | 0 scripts/updater_iqeos.js | 78 +++++++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) rename scripts/{updater.js => updater_eosusd.js} (100%) create mode 100644 scripts/updater_iqeos.js diff --git a/contract/oracle.abi b/contract/oracle.abi index 83f5eca..a66f07e 100644 --- a/contract/oracle.abi +++ b/contract/oracle.abi @@ -1,5 +1,5 @@ { - "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Wed Jul 3 19:48:09 2019", + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Fri Jul 5 20:13:02 2019", "version": "eosio::abi/1.1", "structs": [ { diff --git a/scripts/sample.env b/scripts/sample.env index ccf6006..15b9221 100644 --- a/scripts/sample.env +++ b/scripts/sample.env @@ -3,7 +3,6 @@ EOS_HOST='127.0.0.1' EOS_PORT='8888' EOS_KEY='5J3TQGkkiRQBKcg8Gg2a7Kk5a2QAQXsyGrkCnnq4krSSJSUkW12' EOS_CHAIN='cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f' -ORACLE="feeder111111" CONTRACT="oracle111111" FREQ=60000 ORACLE_PERMISSION="active" \ No newline at end of file diff --git a/scripts/updater.js b/scripts/updater_eosusd.js similarity index 100% rename from scripts/updater.js rename to scripts/updater_eosusd.js diff --git a/scripts/updater_iqeos.js b/scripts/updater_iqeos.js new file mode 100644 index 0000000..d6f3526 --- /dev/null +++ b/scripts/updater_iqeos.js @@ -0,0 +1,78 @@ +const Eos = require('eosjs'); +const dotenv = require('dotenv'); +const axios = require('axios'); + +const url = "https://api.newdex.io/v1/price?symbol=everipediaiq-iq-eos"; +//https://api.newdex.io/v1/price?symbol=everipediaiq-iq-eos +//https://api.newdex.io/v1/price?symbol=thepeostoken-peos-eos +//https://api.newdex.io/v1/price?symbol=betdicetoken-dice-eos +//https://api.newdex.io/v1/price?symbol=eosiotptoken-tpt-eos +//https://min-api.cryptocompare.com/data/price?fsym=EOS&tsyms=USD&e=Kraken +dotenv.load(); + +const interval = process.env.FREQ; +const owner = process.env.ORACLE; +const oracleContract = process.env.CONTRACT; + +const eos = Eos({ + httpEndpoint: process.env.EOS_PROTOCOL + "://" + process.env.EOS_HOST + ":" + process.env.EOS_PORT, + keyProvider: process.env.EOS_KEY, + chainId: process.env.EOS_CHAIN, + verbose:false, + logger: { + log: null, + error: null + } +}); + +function write(){ + + axios.get(`${url}`) + .then(results=>{ + + if (results.data && results.data.data.price){ + + console.log(" results.data.data.price", results.data.data.price); + + eos.contract(oracleContract) + .then((contract) => { + contract.write({ + owner: owner, + quotes:[{value: parseInt(Math.round(results.data.data.price * 1000000)), pair: "iqeos"}] + }, + { + scope: oracleContract, + authorization: [`${owner}@${process.env.ORACLE_PERMISSION || 'active'}`] + }) + .then(results=>{ + console.log("results:", results); + setTimeout(write, interval); + }) + .catch(error=>{ + console.log("error:", error); + setTimeout(write, interval); + }); + + }) + .catch(error=>{ + console.log("error:", error); + setTimeout(write, interval); + }); + + } + else setTimeout(write, interval); + + }) + .catch(error=>{ + console.log("error:", error); + setTimeout(write, interval); + }); + +} + + +write(); + +//setInterval(write, 60000); + + From 94c2feb6e8952afce538eaf8b1aff67debc6d602 Mon Sep 17 00:00:00 2001 From: gg Date: Mon, 8 Jul 2019 20:55:58 -0500 Subject: [PATCH 7/8] added features from the newest delphi, to our version for running local test --- contract/oracle.abi | 72 +++++++++++++++++++-------- contract/oracle.cpp | 100 ++++++++++++++++++++++++++++---------- scripts/updater_eosusd.js | 2 +- 3 files changed, 127 insertions(+), 47 deletions(-) diff --git a/contract/oracle.abi b/contract/oracle.abi index a66f07e..f5be308 100644 --- a/contract/oracle.abi +++ b/contract/oracle.abi @@ -1,5 +1,5 @@ { - "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Fri Jul 5 20:13:02 2019", + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Mon Jul 8 20:46:01 2019", "version": "eosio::abi/1.1", "structs": [ { @@ -53,20 +53,6 @@ } ] }, - { - "name": "extended_symbol", - "base": "", - "fields": [ - { - "name": "symbol", - "type": "symbol" - }, - { - "name": "contract", - "type": "name" - } - ] - }, { "name": "global", "base": "", @@ -86,20 +72,64 @@ "base": "", "fields": [ { - "name": "id", - "type": "uint64" + "name": "active", + "type": "bool" + }, + { + "name": "bounty_awarded", + "type": "bool" + }, + { + "name": "bounty_edited_by_custodians", + "type": "bool" + }, + { + "name": "proposer", + "type": "name" }, { "name": "aname", "type": "name" }, { - "name": "base", - "type": "extended_symbol" + "name": "bounty_amount", + "type": "asset" }, { - "name": "quote", - "type": "extended_symbol" + "name": "approving_custodians", + "type": "name[]" + }, + { + "name": "approving_oracles", + "type": "name[]" + }, + { + "name": "base_symbol", + "type": "symbol" + }, + { + "name": "base_type", + "type": "uint64" + }, + { + "name": "base_contract", + "type": "name" + }, + { + "name": "quote_symbol", + "type": "symbol" + }, + { + "name": "quote_type", + "type": "uint64" + }, + { + "name": "quote_contract", + "type": "name" + }, + { + "name": "quoted_precision", + "type": "uint64" } ] }, diff --git a/contract/oracle.cpp b/contract/oracle.cpp index ceee9f5..6e03287 100644 --- a/contract/oracle.cpp +++ b/contract/oracle.cpp @@ -48,6 +48,15 @@ CONTRACT oracle : public eosio::contract { oracle(name receiver, name code, datastream ds) : eosio::contract(receiver, code, ds) {} //Types + enum asset_type: uint16_t { + fiat=1, + cryptocurrency=2, + erc20_token=3, + eosio_token=4, + equity=5, + derivative=6, + other=7 + }; //Holds the latest datapoints from qualified oracles TABLE datapoints { @@ -87,13 +96,30 @@ CONTRACT oracle : public eosio::contract { //Holds the list of pairs TABLE pairs { - uint64_t id; + + bool active = false; + bool bounty_awarded = false; + bool bounty_edited_by_custodians = false; + + name proposer; name aname; - extended_symbol base; - extended_symbol quote; - uint64_t primary_key() const {return id;} - uint64_t by_name() const {return aname.value;} + asset bounty_amount = asset(0, symbol("EOS",4)); + + std::vector approving_custodians; + std::vector approving_oracles; + + symbol base_symbol; + uint64_t base_type; + name base_contract; + + symbol quote_symbol; + uint64_t quote_type; + name quote_contract; + + uint64_t quoted_precision; + + uint64_t primary_key() const {return aname.value;} }; @@ -156,8 +182,8 @@ CONTRACT oracle : public eosio::contract { typedef eosio::multi_index>> statstable; - typedef eosio::multi_index>> pairstable; + typedef eosio::multi_index pairstable; + typedef eosio::multi_index>, indexed_by>> datapointstable; @@ -394,45 +420,69 @@ typedef eosio::multi_index { contract.write({ owner: owner, - quotes:[{value: parseInt(Math.round((results.data.USD) * 1000000)), pair: "eosusd"}] + quotes:[{value: parseInt(Math.round((results.data.USD) * 10000)), pair: "eosusd"}] }, { scope: oracleContract, From a7f2b482a2eca9552e54ba55a5c574b075ca8fd0 Mon Sep 17 00:00:00 2001 From: gg Date: Sat, 27 Jul 2019 20:00:17 -0500 Subject: [PATCH 8/8] added vigeos --- contract/oracle.abi | 7 ++-- contract/oracle.cpp | 11 ++++++ scripts/updater_vigeos.js | 78 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 scripts/updater_vigeos.js diff --git a/contract/oracle.abi b/contract/oracle.abi index f5be308..7de3994 100644 --- a/contract/oracle.abi +++ b/contract/oracle.abi @@ -1,6 +1,7 @@ { - "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Mon Jul 8 20:46:01 2019", + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", "version": "eosio::abi/1.1", + "types": [], "structs": [ { "name": "claim", @@ -240,7 +241,6 @@ ] } ], - "types": [], "actions": [ { "name": "claim", @@ -306,6 +306,5 @@ } ], "ricardian_clauses": [], - "variants": [], - "abi_extensions": [] + "variants": [] } \ No newline at end of file diff --git a/contract/oracle.cpp b/contract/oracle.cpp index 6e03287..6647c41 100644 --- a/contract/oracle.cpp +++ b/contract/oracle.cpp @@ -485,6 +485,17 @@ typedef eosio::multi_index{ + + if (results.data && results.data.data.price){ + + console.log(" results.data.data.price", results.data.data.price); + + eos.contract(oracleContract) + .then((contract) => { + contract.write({ + owner: owner, + quotes:[{value: parseInt(Math.round(results.data.data.price * 1000000)), pair: "vigeos"}] + }, + { + scope: oracleContract, + authorization: [`${owner}@${process.env.ORACLE_PERMISSION || 'active'}`] + }) + .then(results=>{ + console.log("results:", results); + setTimeout(write, interval); + }) + .catch(error=>{ + console.log("error:", error); + setTimeout(write, interval); + }); + + }) + .catch(error=>{ + console.log("error:", error); + setTimeout(write, interval); + }); + + } + else setTimeout(write, interval); + + }) + .catch(error=>{ + console.log("error:", error); + setTimeout(write, interval); + }); + +} + + +write(); + +//setInterval(write, 60000); + +