Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions src/contracts/TestExampleC.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,47 +341,91 @@ struct TESTEXC : public ContractBase
// Query oracles
if (qpi.tick() % 11 == 1)
{
for (locals.c = (qpi.tick() % 5) + 1; locals.c > 0; --locals.c)
locals.c = (qpi.tick() / 11) % 8;
{
// Setup query (in extra scope limit scope of using namespace Ch
if (locals.c % 3 == 0)
if (locals.c == 0)
{
using namespace Ch;
locals.priceOracleQuery.oracle = OI::Price::getMockOracleId();
locals.priceOracleQuery.currency1 = id(B, T, C, null, null);
locals.priceOracleQuery.currency2 = id(U, S, D, null, null);
locals.priceOracleQuery.timestamp = qpi.now();
}
else if (locals.c % 3 == 1)
else if (locals.c == 1)
{
using namespace Ch;
locals.priceOracleQuery.oracle = OI::Price::getMockOracleId();
locals.priceOracleQuery.oracle = OI::Price::getBinanceOracleId();
locals.priceOracleQuery.currency1 = id(B, T, C, null, null);
locals.priceOracleQuery.currency2 = id(E, T, H, null, null);
locals.priceOracleQuery.timestamp = qpi.now();
}
else
else if (locals.c == 2)
{
using namespace Ch;
locals.priceOracleQuery.oracle = OI::Price::getCoingeckoOracleId();
locals.priceOracleQuery.currency1 = id(B, T, C, null, null);
locals.priceOracleQuery.currency2 = id(U, S, D, T, null);
locals.priceOracleQuery.timestamp = qpi.now();
}
else if (locals.c == 3)
{
using namespace Ch;
locals.priceOracleQuery.oracle = OI::Price::getGateOracleId();
locals.priceOracleQuery.currency1 = id(B, T, C, null, null);
locals.priceOracleQuery.currency2 = id(U, S, D, T, null);
locals.priceOracleQuery.timestamp = qpi.now();
}
else if (locals.c == 4)
{
using namespace Ch;
locals.priceOracleQuery.oracle = OI::Price::getMexcOracleId();
locals.priceOracleQuery.currency1 = id(B, T, C, null, null);
locals.priceOracleQuery.currency2 = id(U, S, D, T, null);
locals.priceOracleQuery.timestamp = qpi.now();
}
else if (locals.c == 5)
{
using namespace Ch;
locals.priceOracleQuery.oracle = OI::Price::getBinanceGateOracleId();
locals.priceOracleQuery.currency1 = id(B, T, C, null, null);
locals.priceOracleQuery.currency2 = id(U, S, D, T, null);
locals.priceOracleQuery.timestamp = qpi.now();
}
else if (locals.c == 6)
{
using namespace Ch;
locals.priceOracleQuery.oracle = OI::Price::getBinanceMexcOracleId();
locals.priceOracleQuery.currency1 = id(B, T, C, null, null);
locals.priceOracleQuery.currency2 = id(U, S, D, T, null);
locals.priceOracleQuery.timestamp = qpi.now();
}
else if (locals.c == 7)
{
using namespace Ch;
locals.priceOracleQuery.oracle = OI::Price::getGateMexcOracleId();
locals.priceOracleQuery.currency1 = id(B, T, C, null, null);
locals.priceOracleQuery.currency2 = id(U, S, D, T, null);
locals.priceOracleQuery.timestamp = qpi.now();
}

locals.oracleQueryId = QUERY_ORACLE(OI::Price, locals.priceOracleQuery, NotifyPriceOracleReply, 60000);
ASSERT(qpi.getOracleQueryStatus(locals.oracleQueryId) == ORACLE_QUERY_STATUS_PENDING);

locals.notificationLog = NotificationLog{ CONTRACT_INDEX, OI::Price::oracleInterfaceIndex, ORACLE_QUERY_STATUS_PENDING, 0, 0, locals.oracleQueryId };
LOG_INFO(locals.notificationLog);
}
}
if (qpi.tick() % 2 == 1)
{
locals.mockOracleQuery.value = qpi.tick();
QUERY_ORACLE(OI::Mock, locals.mockOracleQuery, NotifyMockOracleReply, 20000);
locals.notificationLog = NotificationLog{ CONTRACT_INDEX, OI::Mock::oracleInterfaceIndex, ORACLE_QUERY_STATUS_PENDING, 0, qpi.tick(), locals.oracleQueryId};
for (locals.c = 0; locals.c < (qpi.tick() / 2) % 15; ++locals.c)
{
locals.mockOracleQuery.value = uint64(qpi.tick()) * (locals.c + 1);
QUERY_ORACLE(OI::Mock, locals.mockOracleQuery, NotifyMockOracleReply, 20000);
locals.notificationLog = NotificationLog{ CONTRACT_INDEX, OI::Mock::oracleInterfaceIndex, ORACLE_QUERY_STATUS_PENDING, 0, (sint64)locals.mockOracleQuery.value, locals.oracleQueryId };
LOG_INFO(locals.notificationLog);
}
}
LOG_INFO(locals.notificationLog);
}

//---------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/contracts/qpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace QPI
{
null = 0,
space = ' ', slash = '/', backslash = '\\', dot = '.', comma = ',', colon = ':', semicolon = ';',
underscore = '_', minus = '-', plus = '+', star = '*', dollar = '$', question_mark = '?', exclamation_mark = '!',
a = 'a', b = 'b', c = 'c', d = 'd', e = 'e', f = 'f', g = 'g', h = 'h', i = 'i', j = 'j', k = 'k', l = 'l', m = 'm',
n = 'n', o = 'o', p = 'p', q = 'q', r = 'r', s = 's', t = 't', u = 'u', v = 'v', w = 'w', x = 'x', y = 'y', z = 'z',
A = 'A', B = 'B', C = 'C', D = 'D', E = 'E', F = 'F', G = 'G', H = 'H', I = 'I', J = 'J', K = 'K', L = 'L', M = 'M',
Expand Down
10 changes: 10 additions & 0 deletions src/network_messages/oracles.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ struct RespondOracleData
// The payload is an array of 676 revenue points (one per computer, each 8 bytes).
static constexpr unsigned int respondOracleRevenuePoints = 8;

// The payload is RespondOracleDataValidTickRange.
static constexpr unsigned int respondTickRange = 9;

// type of oracle response
unsigned int resType;
};
Expand Down Expand Up @@ -152,3 +155,10 @@ struct RespondOracleDataQueryStatistics
/// Total number of commit with correct digest but wrong knowledge proof
uint64_t wrongKnowledgeProofCount;
};

// Core node responds with this if the requested query tick is outside the range of ticks with available query info.
struct RespondOracleDataValidTickRange
{
uint32_t firstTick;
uint32_t currentTick;
};
13 changes: 13 additions & 0 deletions src/oracle_core/net_msg_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ void OracleEngine<ownComputorSeedsCount>::processRequestOracleData(Peer* peer, R
case RequestOracleData::requestContractDirectQueryIdsByTick:
case RequestOracleData::requestContractSubscriptionQueryIdsByTick:
{
// check if data for tick is available
if (request->reqTickOrId < system.initialTick || request->reqTickOrId >= system.tick) // TODO: > or >=
{
// data isn't available -> send RespondOracleDataValidTickRange message
response->resType = RespondOracleData::respondTickRange;
auto* payloadTickRange = (RespondOracleDataValidTickRange*)payload;
payloadTickRange->firstTick = system.initialTick;
payloadTickRange->currentTick = system.tick;
enqueueResponse(peer, sizeof(RespondOracleData) + sizeof(RespondOracleDataValidTickRange),
RespondOracleData::type(), header->dejavu(), response);
break;
}

// select filter function for the request type
static_assert(RequestOracleData::requestAllQueryIdsByTick == 0);
static_assert(RequestOracleData::requestUserQueryIdsByTick == 1);
Expand Down
Loading