forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verified betting token configuration
- Loading branch information
1 parent
c59fd49
commit e056498
Showing
11 changed files
with
148 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2023 The Wagerr developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <betting/events.h> | ||
|
||
#include <betting/bet_db.h> | ||
|
||
bool CreateBetEventFromDB(const CBettingsView& bettingsViewCache, const uint32_t nEventId, CBetEvent& event) { | ||
EventKey eventKey{nEventId}; | ||
CPeerlessExtendedEventDB peerlessEventDBItem; | ||
if (bettingsViewCache.events->Read(eventKey, peerlessEventDBItem)) { | ||
event = CBetEvent(BetEventType::PEERLESS, nEventId); | ||
return true; | ||
} | ||
CFieldEventDB fieldEventDBItem; | ||
if (bettingsViewCache.fieldEvents->Read(eventKey, fieldEventDBItem)) { | ||
event = CBetEvent(BetEventType::FIELD, nEventId); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool CBetEvent::IsOpen(const CBettingsView& bettingsViewCache, uint32_t nTime) { | ||
switch (type) | ||
{ | ||
case BetEventType::PEERLESS: | ||
{ | ||
if (bettingsViewCache.results->Exists(ResultKey{nEventId})) { | ||
return error("result for event already posted"); | ||
} | ||
EventKey eventKey{nEventId}; | ||
CPeerlessExtendedEventDB eventDBItem; | ||
if (!bettingsViewCache.events->Read(eventKey, eventDBItem)) { | ||
return false; | ||
} | ||
if (eventDBItem.nStartTime >= nTime) { | ||
return error("past event start time"); | ||
} | ||
break; | ||
} | ||
case BetEventType::FIELD: | ||
{ | ||
if (bettingsViewCache.fieldResults->Exists(FieldResultKey{nEventId})) { | ||
return error("result for event already posted"); | ||
} | ||
EventKey eventKey{nEventId}; | ||
CFieldEventDB eventDBItem; | ||
if (!bettingsViewCache.fieldEvents->Read(eventKey, eventDBItem)) { | ||
return false; | ||
} | ||
if (eventDBItem.nStartTime >= nTime) { | ||
return error("past event start time"); | ||
} | ||
break; | ||
} | ||
default: | ||
return false; | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2023 The Wagerr developers | ||
// Distributed under the MIT/X11 software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef WAGERR_BET_EVENT_H | ||
#define WAGERR_BET_EVENT_H | ||
|
||
#include <betting/bet_common.h> | ||
#include <betting/bet_tx.h> | ||
|
||
#include <array> | ||
#include <string_view> | ||
|
||
class CBettingsView; | ||
|
||
enum class BetEventType : uint8_t { | ||
UNKNOWN = 0x00, | ||
PEERLESS = 0x01, | ||
FIELD = 0x02, | ||
LAST = FIELD | ||
}; | ||
template<> struct is_serializable_enum<BetEventType> : std::true_type {}; | ||
|
||
constexpr std::array<std::string_view, static_cast<uint8_t>(BetEventType::LAST)+1> makeBetEventTypeDefs() { | ||
std::array<std::string_view, static_cast<uint8_t>(BetEventType::LAST)+1> arr = { | ||
"UNKNOWN", | ||
"PEERLESS", | ||
"FIELD" | ||
}; | ||
return arr; | ||
} | ||
[[maybe_unused]] static constexpr auto betEventTypeDefs = makeBetEventTypeDefs(); | ||
|
||
class CBetEvent | ||
{ | ||
public: | ||
BetEventType type; | ||
uint32_t nEventId; | ||
|
||
CBetEvent() : type(BetEventType::UNKNOWN), nEventId(0) {}; | ||
CBetEvent(const CPeerlessEventTx eventTx) : type(BetEventType::PEERLESS), nEventId(eventTx.nEventId) { }; | ||
CBetEvent(const CFieldEventTx eventTx) : type(BetEventType::FIELD), nEventId(eventTx.nEventId) { }; | ||
CBetEvent(const BetEventType type, const uint32_t nEventId) : type(type), nEventId(nEventId) { }; | ||
|
||
bool IsOpen(const CBettingsView& bettingsViewCache, uint32_t nTime); | ||
|
||
}; | ||
|
||
bool CreateBetEventFromDB(const CBettingsView& bettingsViewCache, const uint32_t nEventId, CBetEvent& event); | ||
|
||
#endif // WAGERR_BET_EVENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters