updated pricing record to support timestamps

This commit is contained in:
Neil Coggins
2021-07-20 21:07:54 +01:00
committed by MoneroOcean
parent b402ceb37f
commit d1a0cf9439
5 changed files with 245 additions and 23 deletions
+19 -8
View File
@@ -55,6 +55,7 @@ namespace offshore
uint64_t unused1;
uint64_t unused2;
uint64_t unused3;
uint64_t timestamp;
std::string signature;
BEGIN_KV_SERIALIZE_MAP()
@@ -74,6 +75,7 @@ namespace offshore
KV_SERIALIZE(unused1)
KV_SERIALIZE(unused2)
KV_SERIALIZE(unused3)
KV_SERIALIZE(timestamp)
KV_SERIALIZE(signature)
END_KV_SERIALIZE_MAP()
};
@@ -96,6 +98,7 @@ namespace offshore
, unused1(0)
, unused2(0)
, unused3(0)
, timestamp(0)
{
std::memset(signature, 0, sizeof(signature));
}
@@ -122,6 +125,7 @@ namespace offshore
unused1 = in.unused1;
unused2 = in.unused2;
unused3 = in.unused3;
timestamp = in.timestamp;
for (unsigned int i = 0; i < in.signature.length(); i += 2) {
std::string byteString = in.signature.substr(i, 2);
signature[i>>1] = (char) strtol(byteString.c_str(), NULL, 16);
@@ -141,7 +145,7 @@ namespace offshore
ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature[i]);
sig_hex += ss.str();
}
const pr_serialized out{xAG,xAU,xAUD,xBTC,xCAD,xCHF,xCNY,xEUR,xGBP,xJPY,xNOK,xNZD,xUSD,unused1,unused2,unused3,sig_hex};
const pr_serialized out{xAG,xAU,xAUD,xBTC,xCAD,xCHF,xCNY,xEUR,xGBP,xJPY,xNOK,xNZD,xUSD,unused1,unused2,unused3,timestamp,sig_hex};
return out.store(dest, hparent);
}
@@ -162,6 +166,7 @@ namespace offshore
, unused1(orig.unused1)
, unused2(orig.unused2)
, unused3(orig.unused3)
, timestamp(orig.timestamp)
{
std::memcpy(signature, orig.signature, sizeof(signature));
}
@@ -184,11 +189,12 @@ namespace offshore
unused1 = orig.unused1;
unused2 = orig.unused2;
unused3 = orig.unused3;
timestamp = orig.timestamp;
::memcpy(signature, orig.signature, sizeof(signature));
return *this;
}
uint64_t pricing_record::operator[](const std::string asset_type) const noexcept
uint64_t pricing_record::operator[](const std::string asset_type) const
{
if (asset_type == "XHV") {
return 1000000000000;
@@ -219,7 +225,7 @@ namespace offshore
} else if (asset_type == "XNZD") {
return xNZD;
} else {
return 1000000000000;
CHECK_AND_ASSERT_THROW_MES(false, "Asset type doesn't exist in pricing record!");
}
}
@@ -241,19 +247,22 @@ namespace offshore
(unused1 == other.unused1) &&
(unused2 == other.unused2) &&
(unused3 == other.unused3) &&
(timestamp == other.timestamp) &&
!::memcmp(signature, other.signature, sizeof(signature)));
}
bool pricing_record::is_empty() const noexcept
{
const pricing_record empty_pr = offshore::pricing_record();
return (*this).equal(empty_pr);
}
bool pricing_record::verifySignature(EVP_PKEY* public_key) const noexcept
{
// Sanity check - accept empty pricing records
unsigned char test_sig[64];
std::memset(test_sig, 0, sizeof(test_sig));
if (std::memcmp(test_sig, signature, sizeof(signature)) == 0) {
if ((*this).is_empty())
return true;
}
// Convert our internal 64-byte binary representation into 128-byte hex string
std::string sig_hex;
for (unsigned int i=0; i<64; i++) {
@@ -308,6 +317,8 @@ namespace offshore
oss << ",\"unused1\":" << unused1;
oss << ",\"unused2\":" << unused2;
oss << ",\"unused3\":" << unused3;
if (timestamp > 0)
oss << ",\"timestamp\":" << timestamp;
oss << "}";
std::string message = oss.str();