-
Notifications
You must be signed in to change notification settings - Fork 10
/
checkqueryid.cpp
39 lines (34 loc) · 1.19 KB
/
checkqueryid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#define CONTRACT_NAME "checkqueryid"
#include "provable/eos_api.hpp"
class checkqueryid : public eosio::contract
{
public:
using contract::contract;
checkqueryid(eosio::name receiver, eosio::name code, datastream<const char*> ds) : contract(receiver, code, ds) {}
[[eosio::action]]
void checkquery()
{
eosio::checksum256 myQueryId = provable_query("URL", "json(https://api.kraken.com/0/public/Ticker?pair=EOSUSD).result.EOSUSD.l.0");
provable_queryId_localEmplace(myQueryId);
print(" Provable query was sent & queryId saved in the queryId table as a record, standing by for the answer...");
}
[[eosio::action]]
void callback(
const eosio::checksum256 queryId,
const std::vector<unsigned char> result,
const std::vector<unsigned char> proof
)
{
require_auth(provable_cbAddress());
if (!provable_queryId_match(queryId))
{
// The query Id match has failed, manage this use case...
print(" Unexpected query ID!");
}
else
{
const std::string result_str = vector_to_string(result);
print(" Result: ", result_str);
}
}
};