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.
1
/* INCLUDE ORACLE LOGIC */
2
#include "../dappservices/oracle.hpp"
3
​
4
/* ADD DAPP NETWORK RELATED ORACLE ACTIONS */
5
#define DAPPSERVICES_ACTIONS() \
6
XSIGNAL_DAPPSERVICE_ACTION \
7
ORACLE_DAPPSERVICE_ACTIONS
8
​
9
#define DAPPSERVICE_ACTIONS_COMMANDS() \
10
ORACLE_SVC_COMMANDS()
11
​
12
#define CONTRACT_NAME() oracleconsumer
13
​
14
CONTRACT_START()
15
​
16
/*
17
18
testget - provide a URI using the DAPP Network Oracle syntax and an expected result,
19
if the result does not match the expected field, the transaction fails
20
21
testrnd - fetch oracle request based on URI without expected field assertion
22
23
*/
24
​
25
[[eosio::action]] void testget(std::vector<char> uri, std::vector<char> expectedfield) {
26
/* USE EOSIO'S ASSERTION TO CHECK FOR REQUIRED THREHSHOLD OF ORACLES IS MET */
27
eosio::check(getURI(uri, [&]( auto& results ) {
28
eosio::check(results.size() > 0, "require multiple results for consensus");
29
auto itr = results.begin();
30
auto first = itr->result;
31
++itr;
32
/* SET CONSENSUS LOGIC FOR RESULTS */
33
while(itr != results.end()) {
34
eosio::check(itr->result == first, "consensus failed");
35
++itr;
36
}
37
return first;
38
}) == expectedfield, "wrong data");
39
}
40
41
[[eosio::action]] void testrnd(std::vector<char> uri) {
42
getURI(uri, [&]( auto& results ) {
43
return results[0].result;
44
});
45
}
46
CONTRACT_END((testget)(testrnd))
Copied!
Copy link