L
L
LiquidApps Documentation
Search…
⌃K

Basic Implementation

LiquidHarmony Consumer Example Contract used in unit tests

in zeus_boxes/contracts/eos/oracleconsumer/oracleconsumer.cpp The consumer contract is a great starting point for playing around with the LiquidHarmony syntax.
/* INCLUDE ORACLE LOGIC */
#include "../dappservices/oracle.hpp"
​
/* ADD DAPP NETWORK RELATED ORACLE ACTIONS */
#define DAPPSERVICES_ACTIONS() \
XSIGNAL_DAPPSERVICE_ACTION \
ORACLE_DAPPSERVICE_ACTIONS
​
#define DAPPSERVICE_ACTIONS_COMMANDS() \
ORACLE_SVC_COMMANDS()
​
#define CONTRACT_NAME() oracleconsumer
​
CONTRACT_START()
​
/*
testget - provide a URI using the DAPP Network Oracle syntax and an expected result,
if the result does not match the expected field, the transaction fails
testrnd - fetch oracle request based on URI without expected field assertion
*/
​
[[eosio::action]] void testget(std::vector<char> uri, std::vector<char> expectedfield) {
/* USE EOSIO'S ASSERTION TO CHECK FOR REQUIRED THREHSHOLD OF ORACLES IS MET */
eosio::check(getURI(uri, [&]( auto& results ) {
eosio::check(results.size() > 0, "require multiple results for consensus");
auto itr = results.begin();
auto first = itr->result;
++itr;
/* SET CONSENSUS LOGIC FOR RESULTS */
while(itr != results.end()) {
eosio::check(itr->result == first, "consensus failed");
++itr;
}
return first;
}) == expectedfield, "wrong data");
}
[[eosio::action]] void testrnd(std::vector<char> uri) {
getURI(uri, [&]( auto& results ) {
return results[0].result;
});
}
CONTRACT_END((testget)(testrnd))