Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dd63cb209d | |||
| 161ec204e6 | |||
| 2104ac35d5 | |||
| 30a1cf7813 | |||
| 32dfbcf8ea | |||
| b8d2ba017e | |||
| b18445f6e7 | |||
| bea129bb73 | |||
| 690e900011 | |||
| 516511da69 | |||
| 0aadf3db51 | |||
| be8c2e9c8f | |||
| 66854eb683 | |||
| a9f2317ffa | |||
| eea6d166b2 | |||
| 6bb5e00c17 | |||
| 7bbb0cf80e | |||
| 16f9569d0c | |||
| e6143eb9c0 | |||
| 1b2f6af8f8 | |||
| eb61aefe8b | |||
| 1d0ada1c82 | |||
| 0bb1785826 | |||
| 1c48ad7e46 | |||
| f0c26e6d5b | |||
| 7a1d7271a1 | |||
| 30e051fa46 | |||
| 4ccd4fdca7 | |||
| 71bda2c8bb | |||
| 261c518133 | |||
| 2a1741ac52 | |||
| 1f59698bda |
@@ -7,6 +7,7 @@
|
|||||||
"src/cryptonote_core/cryptonote_format_utils.cpp",
|
"src/cryptonote_core/cryptonote_format_utils.cpp",
|
||||||
"src/offshore/pricing_record.cpp",
|
"src/offshore/pricing_record.cpp",
|
||||||
"src/zephyr_oracle/pricing_record.cpp",
|
"src/zephyr_oracle/pricing_record.cpp",
|
||||||
|
"src/salvium_oracle/pricing_record.cpp",
|
||||||
"src/crypto/tree-hash.c",
|
"src/crypto/tree-hash.c",
|
||||||
"src/crypto/crypto.cpp",
|
"src/crypto/crypto.cpp",
|
||||||
"src/crypto/crypto-ops.c",
|
"src/crypto/crypto-ops.c",
|
||||||
|
|||||||
@@ -46,10 +46,28 @@ function hash256(buffer) {
|
|||||||
return sha256(sha256(buffer));
|
return sha256(sha256(buffer));
|
||||||
};
|
};
|
||||||
|
|
||||||
function getMerkleRoot(transactions) {
|
function sha256_3(buffer) {
|
||||||
|
return crypto.createHash('sha3-256').update(buffer).digest();
|
||||||
|
};
|
||||||
|
|
||||||
|
function hash256_3(buffer) {
|
||||||
|
return sha256_3(sha256_3(buffer));
|
||||||
|
};
|
||||||
|
|
||||||
|
function transaction_hash(transaction, forWitness) {
|
||||||
|
if (forWitness && transaction.isCoinbase()) return Buffer.alloc(32, 0);
|
||||||
|
return hash256(transaction.__toBuffer(undefined, undefined, forWitness));
|
||||||
|
}
|
||||||
|
|
||||||
|
function transaction_hash3(transaction, forWitness) {
|
||||||
|
if (forWitness && transaction.isCoinbase()) return Buffer.alloc(32, 0);
|
||||||
|
return hash256_3(transaction.__toBuffer(undefined, undefined, forWitness));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMerkleRoot(transactions, transaction_hash_func, detectWitness) {
|
||||||
if (transactions.length === 0) return Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
if (transactions.length === 0) return Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
|
||||||
const forWitness = txesHaveWitnessCommit(transactions);
|
const forWitness = detectWitness ? txesHaveWitnessCommit(transactions) : false;
|
||||||
const hashes = transactions.map(transaction => transaction.getHash(forWitness));
|
const hashes = transactions.map(transaction => transaction_hash_func(transaction, forWitness));
|
||||||
const rootHash = fastMerkleRoot(hashes, hash256);
|
const rootHash = fastMerkleRoot(hashes, hash256);
|
||||||
return forWitness ? hash256(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash;
|
return forWitness ? hash256(Buffer.concat([rootHash, transactions[0].ins[0].witness[0]])) : rootHash;
|
||||||
}
|
}
|
||||||
@@ -157,7 +175,7 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function update_merkle_root_hash(offset, payload, blob_in, blob_out) {
|
function update_merkle_root_hash(offset, payload, blob_in, blob_out, transaction_hash_func, detectWitness) {
|
||||||
const nTransactions = varuint.decode(blob_in, offset);
|
const nTransactions = varuint.decode(blob_in, offset);
|
||||||
offset += varuint.decode.bytes;
|
offset += varuint.decode.bytes;
|
||||||
let transactions = [];
|
let transactions = [];
|
||||||
@@ -166,21 +184,25 @@ function update_merkle_root_hash(offset, payload, blob_in, blob_out) {
|
|||||||
transactions.push(tx);
|
transactions.push(tx);
|
||||||
offset += tx.byteLength();
|
offset += tx.byteLength();
|
||||||
}
|
}
|
||||||
getMerkleRoot(transactions).copy(blob_out, 4 + 32);
|
getMerkleRoot(transactions, transaction_hash_func, detectWitness).copy(blob_out, 4 + 32);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.blockHashBuff = function(blobBuffer) {
|
module.exports.blockHashBuff = function(blobBuffer) {
|
||||||
return reverseBuffer(hash256(blobBuffer));
|
return reverseBuffer(hash256(blobBuffer));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.blockHashBuff3 = function(blobBuffer) {
|
||||||
|
return reverseBuffer(hash256_3(blobBuffer));
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.convertRavenBlob = function(blobBuffer) {
|
module.exports.convertRavenBlob = function(blobBuffer) {
|
||||||
let header = blobBuffer.slice(0, 80);
|
let header = blobBuffer.slice(0, 80);
|
||||||
update_merkle_root_hash(80 + 8 + 32, false, blobBuffer, header);
|
update_merkle_root_hash(80 + 8 + 32, false, blobBuffer, header, transaction_hash, true);
|
||||||
return module.exports.blockHashBuff(header);
|
return module.exports.blockHashBuff(header);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
|
module.exports.constructNewRavenBlob = function(blockTemplate, nonceBuff, mixhashBuff) {
|
||||||
update_merkle_root_hash(80 + 8 + 32, false, blockTemplate, blockTemplate);
|
update_merkle_root_hash(80 + 8 + 32, false, blockTemplate, blockTemplate, transaction_hash, true);
|
||||||
nonceBuff.copy (blockTemplate, 80, 0, 8);
|
nonceBuff.copy (blockTemplate, 80, 0, 8);
|
||||||
mixhashBuff.copy(blockTemplate, 88, 0, 32);
|
mixhashBuff.copy(blockTemplate, 88, 0, 32);
|
||||||
return blockTemplate;
|
return blockTemplate;
|
||||||
@@ -217,12 +239,24 @@ module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
|
|
||||||
module.exports.convertRtmBlob = function(blobBuffer) {
|
module.exports.convertRtmBlob = function(blobBuffer) {
|
||||||
let header = blobBuffer.slice(0, 80);
|
let header = blobBuffer.slice(0, 80);
|
||||||
update_merkle_root_hash(80, true, blobBuffer, header);
|
update_merkle_root_hash(80, true, blobBuffer, header, transaction_hash, true);
|
||||||
|
return header;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.convertKcnBlob = function(blobBuffer) {
|
||||||
|
let header = blobBuffer.slice(0, 80);
|
||||||
|
update_merkle_root_hash(80, false, blobBuffer, header, transaction_hash3, false);
|
||||||
return header;
|
return header;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.constructNewRtmBlob = function(blockTemplate, nonceBuff) {
|
module.exports.constructNewRtmBlob = function(blockTemplate, nonceBuff) {
|
||||||
update_merkle_root_hash(80, true, blockTemplate, blockTemplate);
|
update_merkle_root_hash(80, true, blockTemplate, blockTemplate, transaction_hash, true);
|
||||||
|
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
||||||
|
return blockTemplate;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.constructNewKcnBlob = function(blockTemplate, nonceBuff) {
|
||||||
|
update_merkle_root_hash(80, false, blockTemplate, blockTemplate, transaction_hash3, false);
|
||||||
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
nonceBuff.copy(blockTemplate, 76, 0, 4);
|
||||||
return blockTemplate;
|
return blockTemplate;
|
||||||
};
|
};
|
||||||
|
|||||||
+8
-8
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptoforknote-util",
|
"name": "cryptoforknote-util",
|
||||||
"version": "15.3.4",
|
"version": "15.5.7",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
"email": "lucasjonesdev@hotmail.co.uk"
|
"email": "lucasjonesdev@hotmail.co.uk"
|
||||||
@@ -10,16 +10,16 @@
|
|||||||
"url": "https://github.com/haven-protocol-org/node-cryptoforknote-util.git"
|
"url": "https://github.com/haven-protocol-org/node-cryptoforknote-util.git"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"promise": "*",
|
|
||||||
"bindings": "*",
|
|
||||||
"nan": "^2.14.2",
|
|
||||||
"bignum": "^0.13.1",
|
|
||||||
"sha3": "*",
|
|
||||||
"base58-native": "*",
|
"base58-native": "*",
|
||||||
"bech32": "*",
|
"bech32": "*",
|
||||||
"varuint-bitcoin": "^1.0.4",
|
"bignum": "^0.13.1",
|
||||||
|
"bindings": "*",
|
||||||
|
"bitcoinjs-lib": "git+https://github.com/MoneroOcean/bitcoinjs-lib.git",
|
||||||
"merkle-lib": "^2.0.10",
|
"merkle-lib": "^2.0.10",
|
||||||
"bitcoinjs-lib": "git+https://github.com/MoneroOcean/bitcoinjs-lib.git"
|
"nan": "^2.20.0",
|
||||||
|
"promise": "*",
|
||||||
|
"sha3": "*",
|
||||||
|
"varuint-bitcoin": "^1.0.4"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"cryptonight",
|
"cryptonight",
|
||||||
|
|||||||
@@ -149,7 +149,10 @@ function getTransactionBuffers(txs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addressToScript(addr) {
|
function addressToScript(addr) {
|
||||||
const decoded = base58.decode(addr);
|
let decoded;
|
||||||
|
try {
|
||||||
|
decoded = base58.decode(addr);
|
||||||
|
} catch(err) {}
|
||||||
if (!decoded || decoded.length != 25) {
|
if (!decoded || decoded.length != 25) {
|
||||||
const decoded2 = Buffer.from(bech32.bech32.fromWords(bech32.bech32.decode(addr).words.slice(1)));
|
const decoded2 = Buffer.from(bech32.bech32.fromWords(bech32.bech32.decode(addr).words.slice(1)));
|
||||||
if (decoded2.length != 20) throw new Error('Invalid address ' + addr);
|
if (decoded2.length != 20) throw new Error('Invalid address ' + addr);
|
||||||
@@ -159,7 +162,7 @@ function addressToScript(addr) {
|
|||||||
return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), pubkey, Buffer.from([0x88, 0xac])]);
|
return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), pubkey, Buffer.from([0x88, 0xac])]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createOutputTransaction(amount, payee, rewardToPool, reward, txOutputBuffers, payeeScript) {
|
function createTransactionOutput(amount, payee, rewardToPool, reward, txOutputBuffers, payeeScript) {
|
||||||
const payeeReward = amount;
|
const payeeReward = amount;
|
||||||
if (!payeeScript) payeeScript = addressToScript(payee);
|
if (!payeeScript) payeeScript = addressToScript(payee);
|
||||||
txOutputBuffers.push(Buffer.concat([
|
txOutputBuffers.push(Buffer.concat([
|
||||||
@@ -170,25 +173,25 @@ function createOutputTransaction(amount, payee, rewardToPool, reward, txOutputBu
|
|||||||
return { reward: reward - amount, rewardToPool: rewardToPool - amount };
|
return { reward: reward - amount, rewardToPool: rewardToPool - amount };
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateOutputTransactions(rpcData, poolAddress) {
|
function generateTransactionOutputs(rpcData, poolAddress) {
|
||||||
let reward = rpcData.coinbasevalue;
|
let reward = rpcData.coinbasevalue + (rpcData.coinbasedevreward ? rpcData.coinbasedevreward.value : 0);
|
||||||
let rewardToPool = reward;
|
let rewardToPool = reward;
|
||||||
let txOutputBuffers = [];
|
let txOutputBuffers = [];
|
||||||
|
|
||||||
if (rpcData.coinbasedevreward) {
|
if (rpcData.coinbasedevreward) {
|
||||||
const rewards = createOutputTransaction(rpcData.coinbasedevreward.value, rpcData.coinbasedevreward.address, rewardToPool, reward, txOutputBuffers, rpcData.coinbasedevreward.scriptpubkey);
|
const rewards = createTransactionOutput(rpcData.coinbasedevreward.value, null, rewardToPool, reward, txOutputBuffers, Buffer.from(rpcData.coinbasedevreward.scriptpubkey, 'hex'));
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rpcData.smartnode) {
|
if (rpcData.smartnode) {
|
||||||
if (rpcData.smartnode.payee) {
|
if (rpcData.smartnode.payee) {
|
||||||
const rewards = createOutputTransaction(rpcData.smartnode.amount, rpcData.smartnode.payee, rewardToPool, reward, txOutputBuffers);
|
const rewards = createTransactionOutput(rpcData.smartnode.amount, rpcData.smartnode.payee, rewardToPool, reward, txOutputBuffers);
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
} else if (Array.isArray(rpcData.smartnode)) {
|
} else if (Array.isArray(rpcData.smartnode)) {
|
||||||
for (let i in rpcData.smartnode) {
|
for (let i in rpcData.smartnode) {
|
||||||
const rewards = createOutputTransaction(rpcData.smartnode[i].amount, rpcData.smartnode[i].payee, rewardToPool, reward, txOutputBuffers);
|
const rewards = createTransactionOutput(rpcData.smartnode[i].amount, rpcData.smartnode[i].payee, rewardToPool, reward, txOutputBuffers);
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
}
|
}
|
||||||
@@ -197,7 +200,7 @@ function generateOutputTransactions(rpcData, poolAddress) {
|
|||||||
|
|
||||||
if (rpcData.superblock) {
|
if (rpcData.superblock) {
|
||||||
for (let i in rpcData.superblock) {
|
for (let i in rpcData.superblock) {
|
||||||
const rewards = createOutputTransaction(rpcData.superblock[i].amount, rpcData.superblock[i].payee, rewardToPool, reward, txOutputBuffers);
|
const rewards = createTransactionOutput(rpcData.superblock[i].amount, rpcData.superblock[i].payee, rewardToPool, reward, txOutputBuffers);
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
}
|
}
|
||||||
@@ -205,28 +208,28 @@ function generateOutputTransactions(rpcData, poolAddress) {
|
|||||||
|
|
||||||
if (rpcData.founder_payments_started && rpcData.founder) {
|
if (rpcData.founder_payments_started && rpcData.founder) {
|
||||||
const founderReward = rpcData.founder.amount || 0;
|
const founderReward = rpcData.founder.amount || 0;
|
||||||
const rewards = createOutputTransaction(founderReward, rpcData.founder.payee, rewardToPool, reward, txOutputBuffers);
|
const rewards = createTransactionOutput(founderReward, rpcData.founder.payee, rewardToPool, reward, txOutputBuffers);
|
||||||
reward = rewards.reward;
|
reward = rewards.reward;
|
||||||
rewardToPool = rewards.rewardToPool;
|
rewardToPool = rewards.rewardToPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
createOutputTransaction(rewardToPool, null, rewardToPool, reward, txOutputBuffers, Buffer.from(addressToScript(poolAddress), "hex"));
|
createTransactionOutput(rewardToPool, null, rewardToPool, reward, txOutputBuffers, Buffer.from(addressToScript(poolAddress), "hex"));
|
||||||
|
|
||||||
if (rpcData.default_witness_commitment !== undefined) {
|
if (rpcData.default_witness_commitment) {
|
||||||
const witness_commitment = Buffer.from(rpcData.default_witness_commitment, 'hex');
|
createTransactionOutput(0, null, rewardToPool, reward, txOutputBuffers, Buffer.from(rpcData.default_witness_commitment, 'hex'));
|
||||||
txOutputBuffers.unshift(Buffer.concat([
|
txOutputBuffers.push(Buffer.concat([
|
||||||
packInt64LE(0),
|
varIntBuffer(1),
|
||||||
varIntBuffer(witness_commitment.length),
|
varIntBuffer(32),
|
||||||
witness_commitment
|
Buffer.alloc(32, 0)
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Buffer.concat([ varIntBuffer(txOutputBuffers.length), Buffer.concat(txOutputBuffers)]);
|
return Buffer.concat([ varIntBuffer(rpcData.default_witness_commitment ? txOutputBuffers.length - 1 : txOutputBuffers.length), Buffer.concat(txOutputBuffers)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
||||||
const extraNoncePlaceholderLength = 17;
|
const extraNoncePlaceholderLength = 17;
|
||||||
const coinbaseVersion = Buffer.concat([packUInt16LE(3), packUInt16LE(5)]);
|
const coinbaseVersion = rpcData.coinbasedevreward ? Buffer.concat([packUInt16LE(1), packUInt16LE(0)]) : Buffer.concat([packUInt16LE(3), packUInt16LE(5)]);
|
||||||
|
|
||||||
const scriptSigPart1 = Buffer.concat([
|
const scriptSigPart1 = Buffer.concat([
|
||||||
serializeNumber(rpcData.height),
|
serializeNumber(rpcData.height),
|
||||||
@@ -237,9 +240,12 @@ module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
|
|
||||||
const scriptSigPart2 = serializeString('/nodeStratum/');
|
const scriptSigPart2 = serializeString('/nodeStratum/');
|
||||||
|
|
||||||
|
const is_witness = rpcData.default_witness_commitment !== undefined;
|
||||||
|
|
||||||
const blob1 = Buffer.concat([
|
const blob1 = Buffer.concat([
|
||||||
coinbaseVersion,
|
coinbaseVersion,
|
||||||
// transaction input
|
// transaction input
|
||||||
|
Buffer.from(is_witness ? "0001" : "", 'hex'),
|
||||||
varIntBuffer(1), // txInputsCount
|
varIntBuffer(1), // txInputsCount
|
||||||
uint256BufferFromHash(""), // txInPrevOutHash
|
uint256BufferFromHash(""), // txInPrevOutHash
|
||||||
packUInt32LE(Math.pow(2, 32) - 1), // txInPrevOutIndex
|
packUInt32LE(Math.pow(2, 32) - 1), // txInPrevOutIndex
|
||||||
@@ -252,7 +258,7 @@ module.exports.RtmBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
packUInt32LE(0), // txInSequence
|
packUInt32LE(0), // txInSequence
|
||||||
// end transaction input
|
// end transaction input
|
||||||
// transaction output
|
// transaction output
|
||||||
generateOutputTransactions(rpcData, poolAddress),
|
generateTransactionOutputs(rpcData, poolAddress, is_witness),
|
||||||
// end transaction ouput
|
// end transaction ouput
|
||||||
packUInt32LE(0) // txLockTime
|
packUInt32LE(0) // txLockTime
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -36,4 +36,5 @@ enum BLOB_TYPE {
|
|||||||
BLOB_TYPE_CRYPTONOTE_XTA = 12, // ITALO
|
BLOB_TYPE_CRYPTONOTE_XTA = 12, // ITALO
|
||||||
BLOB_TYPE_CRYPTONOTE_ZEPHYR = 13, // ZEPHYR
|
BLOB_TYPE_CRYPTONOTE_ZEPHYR = 13, // ZEPHYR
|
||||||
BLOB_TYPE_CRYPTONOTE_XLA = 14, // XLA
|
BLOB_TYPE_CRYPTONOTE_XLA = 14, // XLA
|
||||||
|
BLOB_TYPE_CRYPTONOTE_SALVIUM= 15, // Salvium
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "serialization/crypto.h"
|
#include "serialization/crypto.h"
|
||||||
#include "serialization/pricing_record.h"
|
#include "serialization/pricing_record.h"
|
||||||
#include "serialization/zephyr_pricing_record.h"
|
#include "serialization/zephyr_pricing_record.h"
|
||||||
|
#include "serialization/salvium_pricing_record.h"
|
||||||
#include "serialization/keyvalue_serialization.h" // eepe named serialization
|
#include "serialization/keyvalue_serialization.h" // eepe named serialization
|
||||||
#include "string_tools.h"
|
#include "string_tools.h"
|
||||||
#include "cryptonote_config.h"
|
#include "cryptonote_config.h"
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
#include "cryptonote_protocol/blobdatatype.h"
|
#include "cryptonote_protocol/blobdatatype.h"
|
||||||
#include "offshore/pricing_record.h"
|
#include "offshore/pricing_record.h"
|
||||||
#include "zephyr_oracle/pricing_record.h"
|
#include "zephyr_oracle/pricing_record.h"
|
||||||
|
#include "salvium_oracle/pricing_record.h"
|
||||||
|
|
||||||
|
|
||||||
namespace cryptonote
|
namespace cryptonote
|
||||||
@@ -48,7 +50,19 @@ namespace cryptonote
|
|||||||
|
|
||||||
typedef std::vector<crypto::signature> ring_signature;
|
typedef std::vector<crypto::signature> ring_signature;
|
||||||
|
|
||||||
|
enum salvium_transaction_type
|
||||||
|
{
|
||||||
|
UNSET = 0,
|
||||||
|
MINER = 1,
|
||||||
|
PROTOCOL = 2,
|
||||||
|
TRANSFER = 3,
|
||||||
|
CONVERT = 4,
|
||||||
|
BURN = 5,
|
||||||
|
STAKE = 6,
|
||||||
|
RETURN = 7,
|
||||||
|
MAX = 7
|
||||||
|
};
|
||||||
|
|
||||||
/* outputs */
|
/* outputs */
|
||||||
|
|
||||||
struct txout_to_script
|
struct txout_to_script
|
||||||
@@ -167,6 +181,41 @@ namespace cryptonote
|
|||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// SALVIUM
|
||||||
|
struct txout_salvium_key
|
||||||
|
{
|
||||||
|
txout_salvium_key() { }
|
||||||
|
txout_salvium_key(const crypto::public_key &_key, const std::string &_asset_type, const uint64_t &_unlock_time) :
|
||||||
|
key(_key), asset_type(_asset_type), unlock_time(_unlock_time) { }
|
||||||
|
crypto::public_key key;
|
||||||
|
std::string asset_type;
|
||||||
|
uint64_t unlock_time;
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
FIELD(key)
|
||||||
|
FIELD(asset_type)
|
||||||
|
VARINT_FIELD(unlock_time)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct txout_salvium_tagged_key
|
||||||
|
{
|
||||||
|
txout_salvium_tagged_key() { }
|
||||||
|
txout_salvium_tagged_key(const crypto::public_key &_key, const std::string &_asset_type, const uint64_t &_unlock_time, const crypto::view_tag &_view_tag) :
|
||||||
|
key(_key), asset_type(_asset_type), unlock_time(_unlock_time), view_tag(_view_tag) { }
|
||||||
|
crypto::public_key key;
|
||||||
|
std::string asset_type;
|
||||||
|
uint64_t unlock_time;
|
||||||
|
crypto::view_tag view_tag; // optimization to reduce scanning time
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
FIELD(key)
|
||||||
|
FIELD(asset_type)
|
||||||
|
VARINT_FIELD(unlock_time)
|
||||||
|
FIELD(view_tag)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
/* inputs */
|
/* inputs */
|
||||||
|
|
||||||
struct txin_gen
|
struct txin_gen
|
||||||
@@ -290,11 +339,28 @@ namespace cryptonote
|
|||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct txin_salvium_key
|
||||||
|
{
|
||||||
|
uint64_t amount;
|
||||||
|
std::string asset_type;
|
||||||
|
std::vector<uint64_t> key_offsets;
|
||||||
|
crypto::key_image k_image; // double spending protection
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
VARINT_FIELD(amount)
|
||||||
|
FIELD(asset_type)
|
||||||
|
FIELD(key_offsets)
|
||||||
|
FIELD(k_image)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore, txin_xasset, txin_haven_key> txin_v;
|
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore, txin_xasset, txin_haven_key> txin_v;
|
||||||
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_zephyr_key> txin_zephyr_v;
|
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_zephyr_key> txin_zephyr_v;
|
||||||
|
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_salvium_key> txin_salvium_v;
|
||||||
|
|
||||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_to_tagged_key> txout_target_v;
|
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_to_tagged_key> txout_target_v;
|
||||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_offshore, txout_xasset, txout_haven_key, txout_haven_tagged_key> txout_xhv_target_v;
|
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_offshore, txout_xasset, txout_haven_key, txout_haven_tagged_key> txout_xhv_target_v;
|
||||||
|
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_salvium_key, txout_salvium_tagged_key> txout_salvium_target_v;
|
||||||
|
|
||||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_zephyr_tagged_key> txout_stablero_target_v;
|
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_zephyr_tagged_key> txout_stablero_target_v;
|
||||||
|
|
||||||
@@ -331,6 +397,17 @@ namespace cryptonote
|
|||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct tx_out_salvium
|
||||||
|
{
|
||||||
|
uint64_t amount;
|
||||||
|
txout_salvium_target_v target;
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
VARINT_FIELD(amount)
|
||||||
|
FIELD(target)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
enum loki_version
|
enum loki_version
|
||||||
{
|
{
|
||||||
@@ -352,9 +429,11 @@ namespace cryptonote
|
|||||||
|
|
||||||
std::vector<txin_v> vin;
|
std::vector<txin_v> vin;
|
||||||
std::vector<txin_zephyr_v> vin_zephyr;
|
std::vector<txin_zephyr_v> vin_zephyr;
|
||||||
|
std::vector<txin_salvium_v> vin_salvium;
|
||||||
std::vector<tx_out> vout;
|
std::vector<tx_out> vout;
|
||||||
std::vector<tx_out_xhv> vout_xhv;
|
std::vector<tx_out_xhv> vout_xhv;
|
||||||
std::vector<tx_out_zephyr> vout_zephyr;
|
std::vector<tx_out_zephyr> vout_zephyr;
|
||||||
|
std::vector<tx_out_salvium> vout_salvium;
|
||||||
//extra
|
//extra
|
||||||
std::vector<uint8_t> extra;
|
std::vector<uint8_t> extra;
|
||||||
// Block height to use PR from
|
// Block height to use PR from
|
||||||
@@ -366,6 +445,23 @@ namespace cryptonote
|
|||||||
std::vector<uint64_t> output_unlock_times;
|
std::vector<uint64_t> output_unlock_times;
|
||||||
std::vector<uint32_t> collateral_indices;
|
std::vector<uint32_t> collateral_indices;
|
||||||
|
|
||||||
|
// SALVIUM-SPECIFIC FIELDS
|
||||||
|
// TX type
|
||||||
|
cryptonote::salvium_transaction_type tx_type;
|
||||||
|
// Return address
|
||||||
|
crypto::public_key return_address;
|
||||||
|
// Return TX public key
|
||||||
|
crypto::public_key return_pubkey;
|
||||||
|
// Source asset type
|
||||||
|
std::string source_asset_type;
|
||||||
|
// Destination asset type (this is only necessary for CONVERT transactions)
|
||||||
|
std::string destination_asset_type;
|
||||||
|
// Circulating supply information - already provided by Haven
|
||||||
|
//uint64_t amount_burnt;
|
||||||
|
// Slippage limit
|
||||||
|
uint64_t amount_slippage_limit;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// NOTE: Loki specific
|
// NOTE: Loki specific
|
||||||
//
|
//
|
||||||
@@ -629,7 +725,27 @@ namespace cryptonote
|
|||||||
VARINT_FIELD(pricing_record_height)
|
VARINT_FIELD(pricing_record_height)
|
||||||
VARINT_FIELD(amount_burnt)
|
VARINT_FIELD(amount_burnt)
|
||||||
VARINT_FIELD(amount_minted)
|
VARINT_FIELD(amount_minted)
|
||||||
|
|
||||||
|
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) {
|
||||||
|
|
||||||
|
VARINT_FIELD(version)
|
||||||
|
//if(version == 0 || CURRENT_TRANSACTION_VERSION < version) return false;
|
||||||
|
VARINT_FIELD(unlock_time)
|
||||||
|
FIELD(vin_salvium)
|
||||||
|
FIELD(vout_salvium)
|
||||||
|
FIELD(extra)
|
||||||
|
VARINT_FIELD(tx_type)
|
||||||
|
if (tx_type != cryptonote::salvium_transaction_type::PROTOCOL) {
|
||||||
|
VARINT_FIELD(amount_burnt)
|
||||||
|
if (tx_type != cryptonote::salvium_transaction_type::MINER) {
|
||||||
|
FIELD(return_address)
|
||||||
|
FIELD(return_pubkey)
|
||||||
|
FIELD(source_asset_type)
|
||||||
|
FIELD(destination_asset_type)
|
||||||
|
VARINT_FIELD(amount_slippage_limit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
VARINT_FIELD(version)
|
VARINT_FIELD(version)
|
||||||
@@ -722,7 +838,7 @@ namespace cryptonote
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ar.tag("rct_signatures");
|
ar.tag("rct_signatures");
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? !vin_zephyr.empty() : !vin.empty())
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? !vin_salvium.empty() : (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? !vin_zephyr.empty() : !vin.empty()))
|
||||||
{
|
{
|
||||||
ar.begin_object();
|
ar.begin_object();
|
||||||
bool r;
|
bool r;
|
||||||
@@ -730,6 +846,8 @@ namespace cryptonote
|
|||||||
r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout_xhv.size());
|
r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout_xhv.size());
|
||||||
else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
||||||
r = rct_signatures.serialize_rctsig_base(ar, vin_zephyr.size(), vout_zephyr.size());
|
r = rct_signatures.serialize_rctsig_base(ar, vin_zephyr.size(), vout_zephyr.size());
|
||||||
|
else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM)
|
||||||
|
r = rct_signatures.serialize_rctsig_base(ar, vin_salvium.size(), vout_salvium.size());
|
||||||
else
|
else
|
||||||
r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size());
|
r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size());
|
||||||
if (!r || !ar.stream().good()) return false;
|
if (!r || !ar.stream().good()) return false;
|
||||||
@@ -741,6 +859,9 @@ namespace cryptonote
|
|||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin_zephyr.size(), vout_zephyr.size(),
|
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin_zephyr.size(), vout_zephyr.size(),
|
||||||
vin_zephyr[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(vin_zephyr[0]).key_offsets.size() - 1 : 0);
|
vin_zephyr[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(vin_zephyr[0]).key_offsets.size() - 1 : 0);
|
||||||
|
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) {
|
||||||
|
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin_salvium.size(), vout_salvium.size(),
|
||||||
|
vin_salvium[0].type() == typeid(txin_salvium_key) ? boost::get<txin_salvium_key>(vin_salvium[0]).key_offsets.size() - 1 : 0);
|
||||||
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout_xhv.size(),
|
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout_xhv.size(),
|
||||||
vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 :
|
vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 :
|
||||||
@@ -932,6 +1053,7 @@ namespace cryptonote
|
|||||||
uint64_t nonce8;
|
uint64_t nonce8;
|
||||||
offshore::pricing_record pricing_record;
|
offshore::pricing_record pricing_record;
|
||||||
zephyr_oracle::pricing_record zephyr_pricing_record;
|
zephyr_oracle::pricing_record zephyr_pricing_record;
|
||||||
|
salvium_oracle::pricing_record salvium_pricing_record;
|
||||||
crypto::cycle cycle;
|
crypto::cycle cycle;
|
||||||
crypto::cycle40 cycle40;
|
crypto::cycle40 cycle40;
|
||||||
crypto::cycle48 cycle48;
|
crypto::cycle48 cycle48;
|
||||||
@@ -957,11 +1079,26 @@ namespace cryptonote
|
|||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(cycle40)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(cycle40)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(cycle48)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(cycle48)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) FIELD(pricing_record)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) FIELD(pricing_record)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) FIELD(salvium_pricing_record)
|
||||||
if (major_version >= 3)
|
else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||||
|
if (major_version >= 4)
|
||||||
{
|
{
|
||||||
FIELD_N("pricing_record", zephyr_pricing_record)
|
FIELD_N("pricing_record", zephyr_pricing_record)
|
||||||
}
|
}
|
||||||
|
else if (major_version >= 3)
|
||||||
|
{
|
||||||
|
zephyr_oracle::pricing_record_v2 pr_v2;
|
||||||
|
if (!typename Archive<W>::is_saving())
|
||||||
|
{
|
||||||
|
FIELD(pr_v2)
|
||||||
|
pr_v2.write_to_pr(zephyr_pricing_record);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pr_v2.read_from_pr(zephyr_pricing_record);
|
||||||
|
FIELD(pr_v2)
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zephyr_oracle::pricing_record_v1 pr_v1;
|
zephyr_oracle::pricing_record_v1 pr_v1;
|
||||||
@@ -987,10 +1124,11 @@ namespace cryptonote
|
|||||||
bytecoin_block parent_block;
|
bytecoin_block parent_block;
|
||||||
|
|
||||||
transaction miner_tx;
|
transaction miner_tx;
|
||||||
|
transaction protocol_tx;
|
||||||
std::vector<crypto::hash> tx_hashes;
|
std::vector<crypto::hash> tx_hashes;
|
||||||
mutable crypto::hash uncle = cryptonote::null_hash;
|
mutable crypto::hash uncle = cryptonote::null_hash;
|
||||||
|
|
||||||
void set_blob_type(enum BLOB_TYPE bt) { miner_tx.blob_type = blob_type = bt; }
|
void set_blob_type(enum BLOB_TYPE bt) { miner_tx.blob_type = protocol_tx.blob_type = blob_type = bt; }
|
||||||
|
|
||||||
BEGIN_SERIALIZE_OBJECT()
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
FIELDS(*static_cast<block_header *>(this))
|
FIELDS(*static_cast<block_header *>(this))
|
||||||
@@ -1000,6 +1138,10 @@ namespace cryptonote
|
|||||||
FIELD_N("parent_block", sbb);
|
FIELD_N("parent_block", sbb);
|
||||||
}
|
}
|
||||||
FIELD(miner_tx)
|
FIELD(miner_tx)
|
||||||
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM)
|
||||||
|
{
|
||||||
|
FIELD(protocol_tx)
|
||||||
|
}
|
||||||
FIELD(tx_hashes)
|
FIELD(tx_hashes)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE3)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE3)
|
||||||
{
|
{
|
||||||
@@ -1061,14 +1203,17 @@ VARIANT_TAG(binary_archive, cryptonote::txin_to_scripthash, 0x1);
|
|||||||
VARIANT_TAG(binary_archive, cryptonote::txin_to_key, 0x2);
|
VARIANT_TAG(binary_archive, cryptonote::txin_to_key, 0x2);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txin_zephyr_key, 0x2);
|
VARIANT_TAG(binary_archive, cryptonote::txin_zephyr_key, 0x2);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txin_offshore, 0x3);
|
VARIANT_TAG(binary_archive, cryptonote::txin_offshore, 0x3);
|
||||||
|
VARIANT_TAG(binary_archive, cryptonote::txin_salvium_key, 0x2);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txin_onshore, 0x4);
|
VARIANT_TAG(binary_archive, cryptonote::txin_onshore, 0x4);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txin_xasset, 0x5);
|
VARIANT_TAG(binary_archive, cryptonote::txin_xasset, 0x5);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txin_haven_key, 0x6);
|
VARIANT_TAG(binary_archive, cryptonote::txin_haven_key, 0x6);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_to_script, 0x0);
|
VARIANT_TAG(binary_archive, cryptonote::txout_to_script, 0x0);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1);
|
VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2);
|
VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2);
|
||||||
|
VARIANT_TAG(binary_archive, cryptonote::txout_salvium_key, 0x2);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_zephyr_tagged_key, 0x2);
|
VARIANT_TAG(binary_archive, cryptonote::txout_zephyr_tagged_key, 0x2);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_to_tagged_key, 0x3);
|
VARIANT_TAG(binary_archive, cryptonote::txout_to_tagged_key, 0x3);
|
||||||
|
VARIANT_TAG(binary_archive, cryptonote::txout_salvium_tagged_key, 0x3);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_offshore, 0x3);
|
VARIANT_TAG(binary_archive, cryptonote::txout_offshore, 0x3);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_xasset, 0x5);
|
VARIANT_TAG(binary_archive, cryptonote::txout_xasset, 0x5);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_haven_key, 0x6);
|
VARIANT_TAG(binary_archive, cryptonote::txout_haven_key, 0x6);
|
||||||
|
|||||||
@@ -220,8 +220,8 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
binary_archive<true> ba(ss);
|
binary_archive<true> ba(ss);
|
||||||
const size_t inputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vin_zephyr.size() : t.vin.size();
|
const size_t inputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vin_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vin_zephyr.size() : t.vin.size());
|
||||||
const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size();
|
const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vout_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : (t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size()));
|
||||||
bool r = tt.rct_signatures.serialize_rctsig_base(ba, inputs, outputs);
|
bool r = tt.rct_signatures.serialize_rctsig_base(ba, inputs, outputs);
|
||||||
CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures base");
|
CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures base");
|
||||||
cryptonote::get_blob_hash(ss.str(), hashes[1]);
|
cryptonote::get_blob_hash(ss.str(), hashes[1]);
|
||||||
@@ -236,10 +236,12 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
binary_archive<true> ba(ss);
|
binary_archive<true> ba(ss);
|
||||||
const size_t inputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vin_zephyr.size() : t.vin.size();
|
const size_t inputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vin_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vin_zephyr.size() : t.vin.size());
|
||||||
const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size();
|
const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vout_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : (t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size()));
|
||||||
size_t mixin;
|
size_t mixin;
|
||||||
if (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
if (t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) {
|
||||||
|
mixin = t.vin_salvium.empty() ? 0 : t.vin_salvium[0].type() == typeid(txin_salvium_key) ? boost::get<txin_salvium_key>(t.vin_salvium[0]).key_offsets.size() - 1 : 0;
|
||||||
|
} else if (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||||
mixin = t.vin_zephyr.empty() ? 0 : t.vin_zephyr[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(t.vin_zephyr[0]).key_offsets.size() - 1 : 0;
|
mixin = t.vin_zephyr.empty() ? 0 : t.vin_zephyr[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(t.vin_zephyr[0]).key_offsets.size() - 1 : 0;
|
||||||
} else if (t.blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
} else if (t.blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||||
mixin = t.vin.empty() ? 0 :
|
mixin = t.vin.empty() ? 0 :
|
||||||
@@ -285,7 +287,11 @@ namespace cryptonote
|
|||||||
}
|
}
|
||||||
crypto::hash tree_root_hash = get_tx_tree_hash(b);
|
crypto::hash tree_root_hash = get_tx_tree_hash(b);
|
||||||
blob.append(reinterpret_cast<const char*>(&tree_root_hash), sizeof(tree_root_hash));
|
blob.append(reinterpret_cast<const char*>(&tree_root_hash), sizeof(tree_root_hash));
|
||||||
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
|
if (b.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) {
|
||||||
|
blob.append(tools::get_varint_data(b.tx_hashes.size()+2));
|
||||||
|
} else {
|
||||||
|
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
|
||||||
|
}
|
||||||
if (b.blob_type == BLOB_TYPE_CRYPTONOTE3) {
|
if (b.blob_type == BLOB_TYPE_CRYPTONOTE3) {
|
||||||
blob.append(reinterpret_cast<const char*>(&b.uncle), sizeof(b.uncle));
|
blob.append(reinterpret_cast<const char*>(&b.uncle), sizeof(b.uncle));
|
||||||
}
|
}
|
||||||
@@ -413,6 +419,12 @@ namespace cryptonote
|
|||||||
crypto::hash h = null_hash;
|
crypto::hash h = null_hash;
|
||||||
size_t bl_sz = 0;
|
size_t bl_sz = 0;
|
||||||
get_transaction_hash(b.miner_tx, h, bl_sz);
|
get_transaction_hash(b.miner_tx, h, bl_sz);
|
||||||
|
if (b.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) {
|
||||||
|
txs_ids.push_back(h);
|
||||||
|
h = null_hash;
|
||||||
|
bl_sz = 0;
|
||||||
|
get_transaction_hash(b.protocol_tx, h, bl_sz);
|
||||||
|
}
|
||||||
txs_ids.push_back(h);
|
txs_ids.push_back(h);
|
||||||
BOOST_FOREACH(auto& th, b.tx_hashes)
|
BOOST_FOREACH(auto& th, b.tx_hashes)
|
||||||
txs_ids.push_back(th);
|
txs_ids.push_back(th);
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ namespace rct {
|
|||||||
typedef std::vector<key> keyV; //vector of keys
|
typedef std::vector<key> keyV; //vector of keys
|
||||||
typedef std::vector<keyV> keyM; //matrix of keys (indexed by column first)
|
typedef std::vector<keyV> keyM; //matrix of keys (indexed by column first)
|
||||||
|
|
||||||
|
static key null_key = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||||
|
|
||||||
//containers For CT operations
|
//containers For CT operations
|
||||||
//if it's representing a private ctkey then "dest" contains the secret key of the address
|
//if it's representing a private ctkey then "dest" contains the secret key of the address
|
||||||
// while "mask" contains a where C = aG + bH is CT pedersen commitment and b is the amount
|
// while "mask" contains a where C = aG + bH is CT pedersen commitment and b is the amount
|
||||||
@@ -325,6 +327,7 @@ namespace rct {
|
|||||||
xmr_amount txnOffshoreFee_usd = 0;
|
xmr_amount txnOffshoreFee_usd = 0;
|
||||||
xmr_amount txnOffshoreFee_xasset = 0;
|
xmr_amount txnOffshoreFee_xasset = 0;
|
||||||
keyV maskSums; // contains 2 or 3 elements. 1. is the sum of masks of inputs. 2. is the sum of masks of change outputs. 3. mask of the col output.
|
keyV maskSums; // contains 2 or 3 elements. 1. is the sum of masks of inputs. 2. is the sum of masks of change outputs. 3. mask of the col output.
|
||||||
|
key p_r;
|
||||||
|
|
||||||
template<bool W, template <bool> class Archive>
|
template<bool W, template <bool> class Archive>
|
||||||
bool serialize_rctsig_base(Archive<W> &ar, size_t inputs, size_t outputs)
|
bool serialize_rctsig_base(Archive<W> &ar, size_t inputs, size_t outputs)
|
||||||
@@ -384,6 +387,8 @@ namespace rct {
|
|||||||
FIELDS(maskSums[2])
|
FIELDS(maskSums[2])
|
||||||
ar.end_array();
|
ar.end_array();
|
||||||
}
|
}
|
||||||
|
if (crypto_verify_32(p_r.bytes, null_key.bytes))
|
||||||
|
FIELD(p_r)
|
||||||
return ar.stream().good();
|
return ar.stream().good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// Copyright (c) 2021, Haven Protocol
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace salvium_oracle {
|
||||||
|
|
||||||
|
const std::vector<std::string> ASSET_TYPES = {"SAL", "VSD", "BURN"};
|
||||||
|
|
||||||
|
class asset_type_counts
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Fields
|
||||||
|
uint64_t SAL;
|
||||||
|
uint64_t VSD;
|
||||||
|
uint64_t BURN;
|
||||||
|
|
||||||
|
asset_type_counts() noexcept
|
||||||
|
: SAL(0)
|
||||||
|
, VSD(0)
|
||||||
|
, BURN(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t operator[](const std::string asset_type) const noexcept
|
||||||
|
{
|
||||||
|
if (asset_type == "SAL") {
|
||||||
|
return SAL;
|
||||||
|
} else if (asset_type == "VSD") {
|
||||||
|
return VSD;
|
||||||
|
} else if (asset_type == "BURN") {
|
||||||
|
return BURN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add(const std::string asset_type, const uint64_t val)
|
||||||
|
{
|
||||||
|
if (asset_type == "SAL") {
|
||||||
|
SAL += val;
|
||||||
|
} else if (asset_type == "VSD") {
|
||||||
|
VSD += val;
|
||||||
|
} else if (asset_type == "BURN") {
|
||||||
|
BURN += val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,316 @@
|
|||||||
|
// Copyright (c) 2019, Haven Protocol
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Portions of this code based upon code Copyright (c) 2019, The Monero Project
|
||||||
|
|
||||||
|
#include <boost/multiprecision/cpp_int.hpp>
|
||||||
|
#include "pricing_record.h"
|
||||||
|
|
||||||
|
#include "serialization/keyvalue_serialization.h"
|
||||||
|
#include "storages/portable_storage.h"
|
||||||
|
|
||||||
|
#include "string_tools.h"
|
||||||
|
namespace salvium_oracle
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct asset_data_serialized
|
||||||
|
{
|
||||||
|
std::string asset_type;
|
||||||
|
uint64_t spot_price;
|
||||||
|
uint64_t ma_price;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(asset_type)
|
||||||
|
KV_SERIALIZE(spot_price)
|
||||||
|
KV_SERIALIZE(ma_price)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct supply_data_serialized
|
||||||
|
{
|
||||||
|
uint64_t SAL;
|
||||||
|
uint64_t VSD;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(SAL)
|
||||||
|
KV_SERIALIZE(VSD)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pr_serialized
|
||||||
|
{
|
||||||
|
uint64_t pr_version;
|
||||||
|
uint64_t height;
|
||||||
|
supply_data supply;
|
||||||
|
std::vector<asset_data> assets;
|
||||||
|
uint64_t timestamp;
|
||||||
|
std::string signature;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(pr_version)
|
||||||
|
KV_SERIALIZE(height)
|
||||||
|
KV_SERIALIZE(supply)
|
||||||
|
KV_SERIALIZE(assets)
|
||||||
|
KV_SERIALIZE(timestamp)
|
||||||
|
KV_SERIALIZE(signature)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pricing_record::pricing_record() noexcept
|
||||||
|
: pr_version(0)
|
||||||
|
, height(0)
|
||||||
|
, supply()
|
||||||
|
, assets()
|
||||||
|
, timestamp(0)
|
||||||
|
, signature()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
pricing_record::~pricing_record() noexcept
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool supply_data::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent)
|
||||||
|
{
|
||||||
|
supply_data_serialized in{};
|
||||||
|
if (in._load(src, hparent))
|
||||||
|
{
|
||||||
|
// Copy everything into the local instance
|
||||||
|
sal = in.SAL;
|
||||||
|
vsd = in.VSD;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Report error here?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool supply_data::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
|
||||||
|
{
|
||||||
|
const supply_data_serialized out{sal, vsd};
|
||||||
|
return out.store(dest, hparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool asset_data::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent)
|
||||||
|
{
|
||||||
|
asset_data_serialized in{};
|
||||||
|
if (in._load(src, hparent))
|
||||||
|
{
|
||||||
|
// Copy everything into the local instance
|
||||||
|
asset_type = in.asset_type;
|
||||||
|
spot_price = in.spot_price;
|
||||||
|
ma_price = in.ma_price;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Report error here?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool asset_data::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
|
||||||
|
{
|
||||||
|
const asset_data_serialized out{asset_type, spot_price, ma_price};
|
||||||
|
return out.store(dest, hparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent)
|
||||||
|
{
|
||||||
|
pr_serialized in{};
|
||||||
|
if (in._load(src, hparent))
|
||||||
|
{
|
||||||
|
// Copy everything into the local instance
|
||||||
|
pr_version = in.pr_version;
|
||||||
|
height = in.height;
|
||||||
|
supply = in.supply;
|
||||||
|
assets = in.assets;
|
||||||
|
timestamp = in.timestamp;
|
||||||
|
|
||||||
|
// Signature arrives in HEX format, but needs to be used in BINARY format - convert it here
|
||||||
|
signature.resize(0);
|
||||||
|
assert(in.signature.size()%2 == 0);
|
||||||
|
signature.reserve(in.signature.size() >> 1);
|
||||||
|
for (unsigned int i = 0; i < in.signature.size(); i += 2) {
|
||||||
|
std::string byteString = in.signature.substr(i, 2);
|
||||||
|
signature.emplace_back((uint8_t)strtol(byteString.c_str(), NULL, 16));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Report error here?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
|
||||||
|
{
|
||||||
|
std::string sig_hex;
|
||||||
|
for (size_t i=0; i<signature.size(); ++i) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature.at(i));
|
||||||
|
sig_hex += ss.str();
|
||||||
|
}
|
||||||
|
const pr_serialized out{pr_version, height, supply, assets, timestamp, sig_hex};
|
||||||
|
return out.store(dest, hparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
pricing_record::pricing_record(const pricing_record& orig) noexcept
|
||||||
|
: pr_version(orig.pr_version)
|
||||||
|
, height(orig.height)
|
||||||
|
, supply(orig.supply)
|
||||||
|
, assets(orig.assets)
|
||||||
|
, timestamp(orig.timestamp)
|
||||||
|
, signature(orig.signature)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
pricing_record& pricing_record::operator=(const pricing_record& orig) noexcept
|
||||||
|
{
|
||||||
|
pr_version = orig.pr_version;
|
||||||
|
height = orig.height;
|
||||||
|
supply = orig.supply;
|
||||||
|
assets = orig.assets;
|
||||||
|
timestamp = orig.timestamp;
|
||||||
|
signature = orig.signature;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t pricing_record::operator[](const std::string& asset_type) const
|
||||||
|
{
|
||||||
|
for (const auto& asset: assets) {
|
||||||
|
if (asset.asset_type != asset_type) continue;
|
||||||
|
return asset.spot_price;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::equal(const pricing_record& other) const noexcept
|
||||||
|
{
|
||||||
|
return ((pr_version == other.pr_version) &&
|
||||||
|
(height == other.height) &&
|
||||||
|
(supply == other.supply) &&
|
||||||
|
(assets == other.assets) &&
|
||||||
|
(timestamp == other.timestamp) &&
|
||||||
|
(signature == other.signature));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::empty() const noexcept
|
||||||
|
{
|
||||||
|
const pricing_record empty_pr = salvium_oracle::pricing_record();
|
||||||
|
return (*this).equal(empty_pr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::verifySignature(const std::string& public_key) const
|
||||||
|
{
|
||||||
|
CHECK_AND_ASSERT_THROW_MES(!public_key.empty(), "Pricing record verification failed. NULL public key. PK Size: " << public_key.size());
|
||||||
|
|
||||||
|
// extract the key
|
||||||
|
EVP_PKEY* pubkey;
|
||||||
|
BIO* bio = BIO_new_mem_buf(public_key.c_str(), public_key.size());
|
||||||
|
if (!bio) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pubkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL);
|
||||||
|
BIO_free(bio);
|
||||||
|
CHECK_AND_ASSERT_THROW_MES(pubkey != NULL, "Pricing record verification failed. NULL public key.");
|
||||||
|
|
||||||
|
// Build the JSON string, so that we can verify the signature
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "{\"pr_version\":" << pr_version;
|
||||||
|
oss << ",\"height\":" << height;
|
||||||
|
oss << ",\"supply\":{\"SAL\":" << supply.sal <<",\"VSD\":" << supply.vsd << "}";
|
||||||
|
oss << ",\"assets\":[";
|
||||||
|
bool first = true;
|
||||||
|
for (const auto& asset: assets) {
|
||||||
|
if (first)
|
||||||
|
first=false;
|
||||||
|
else
|
||||||
|
oss << ",";
|
||||||
|
oss << "{\"asset_type\":\"" << asset.asset_type << "\",\"spot_price\":" << asset.spot_price << ",\"ma_price\":" << asset.ma_price << "}";
|
||||||
|
}
|
||||||
|
oss << "]";
|
||||||
|
oss << ",\"timestamp\":" << timestamp;
|
||||||
|
oss << "}";
|
||||||
|
std::string message = oss.str();
|
||||||
|
|
||||||
|
// Create a verify digest from the message
|
||||||
|
EVP_MD_CTX *ctx = EVP_MD_CTX_create();
|
||||||
|
int ret = 0;
|
||||||
|
if (ctx) {
|
||||||
|
ret = EVP_DigestVerifyInit(ctx, NULL, EVP_sha256(), NULL, pubkey);
|
||||||
|
if (ret == 1) {
|
||||||
|
ret = EVP_DigestVerifyUpdate(ctx, message.data(), message.length());
|
||||||
|
if (ret == 1) {
|
||||||
|
ret = EVP_DigestVerifyFinal(ctx, (const unsigned char *)signature.data(), signature.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup the context we created
|
||||||
|
EVP_MD_CTX_destroy(ctx);
|
||||||
|
// Cleanup the openssl stuff
|
||||||
|
EVP_PKEY_free(pubkey);
|
||||||
|
|
||||||
|
if (ret == 1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Get the errors from OpenSSL
|
||||||
|
ERR_print_errors_fp (stderr);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// overload for pr validation for block
|
||||||
|
bool pricing_record::valid(cryptonote::network_type nettype, uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const
|
||||||
|
{
|
||||||
|
if (hf_version < HF_VERSION_SLIPPAGE_YIELD) {
|
||||||
|
if (!this->empty())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->empty())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!verifySignature(get_config(nettype).ORACLE_PUBLIC_KEY)) {
|
||||||
|
LOG_ERROR("Invalid pricing record signature.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate the timestmap
|
||||||
|
if (this->timestamp > bl_timestamp + PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK) {
|
||||||
|
LOG_ERROR("Pricing record timestamp is too far in the future.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->timestamp <= last_bl_timestamp) {
|
||||||
|
LOG_ERROR("Pricing record timestamp: " << this->timestamp << ", block timestamp: " << bl_timestamp);
|
||||||
|
LOG_ERROR("Pricing record timestamp is too old.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
// Copyright (c) 2019, Haven Protocol
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Portions of this code based upon code Copyright (c) 2019, The Monero Project
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "common/pod-class.h"
|
||||||
|
|
||||||
|
#include <openssl/bio.h>
|
||||||
|
#include <openssl/crypto.h>
|
||||||
|
#include <openssl/ecdsa.h>
|
||||||
|
#include <openssl/err.h>
|
||||||
|
#include <openssl/evp.h>
|
||||||
|
#include <openssl/pem.h>
|
||||||
|
#include <openssl/rsa.h>
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <cstring>
|
||||||
|
#include "serialization/containers.h"
|
||||||
|
|
||||||
|
#include "cryptonote_config.h"
|
||||||
|
#include "crypto/hash.h"
|
||||||
|
|
||||||
|
namespace epee
|
||||||
|
{
|
||||||
|
namespace serialization
|
||||||
|
{
|
||||||
|
class portable_storage;
|
||||||
|
struct section;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace salvium_oracle
|
||||||
|
{
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
POD_CLASS pricing_record_pre {
|
||||||
|
uint64_t pr_version;
|
||||||
|
uint64_t price;
|
||||||
|
uint64_t timestamp;
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
struct supply_data {
|
||||||
|
uint64_t sal;
|
||||||
|
uint64_t vsd;
|
||||||
|
|
||||||
|
//! Load from epee p2p format
|
||||||
|
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
||||||
|
//! Store in epee p2p format
|
||||||
|
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
VARINT_FIELD(sal)
|
||||||
|
VARINT_FIELD(vsd)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const supply_data& a, const supply_data& b) noexcept
|
||||||
|
{
|
||||||
|
return (a.sal == b.sal &&
|
||||||
|
a.vsd == b.vsd);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct asset_data {
|
||||||
|
std::string asset_type;
|
||||||
|
uint64_t spot_price;
|
||||||
|
uint64_t ma_price;
|
||||||
|
|
||||||
|
//! Load from epee p2p format
|
||||||
|
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
||||||
|
//! Store in epee p2p format
|
||||||
|
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
FIELD(asset_type)
|
||||||
|
VARINT_FIELD(spot_price)
|
||||||
|
VARINT_FIELD(ma_price)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const asset_data& a, const asset_data& b) noexcept
|
||||||
|
{
|
||||||
|
return (a.asset_type == b.asset_type &&
|
||||||
|
a.spot_price == b.spot_price &&
|
||||||
|
a.ma_price == b.ma_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pricing_record
|
||||||
|
{
|
||||||
|
// Fields
|
||||||
|
uint64_t pr_version;
|
||||||
|
uint64_t height;
|
||||||
|
supply_data supply;
|
||||||
|
std::vector<asset_data> assets;
|
||||||
|
uint64_t timestamp;
|
||||||
|
std::vector<uint8_t> signature;
|
||||||
|
|
||||||
|
// Default c'tor
|
||||||
|
pricing_record() noexcept;
|
||||||
|
//! Load from epee p2p format
|
||||||
|
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
||||||
|
//! Store in epee p2p format
|
||||||
|
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
||||||
|
pricing_record(const pricing_record& orig) noexcept;
|
||||||
|
~pricing_record() noexcept;
|
||||||
|
bool equal(const pricing_record& other) const noexcept;
|
||||||
|
bool empty() const noexcept;
|
||||||
|
bool verifySignature(const std::string& public_key) const;
|
||||||
|
bool valid(cryptonote::network_type nettype, uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const;
|
||||||
|
|
||||||
|
pricing_record& operator=(const pricing_record& orig) noexcept;
|
||||||
|
uint64_t operator[](const std::string& asset_type) const;
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
VARINT_FIELD(pr_version)
|
||||||
|
VARINT_FIELD(height)
|
||||||
|
FIELD(supply)
|
||||||
|
FIELD(assets)
|
||||||
|
VARINT_FIELD(timestamp)
|
||||||
|
FIELD(signature)
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const pricing_record& a, const pricing_record& b) noexcept
|
||||||
|
{
|
||||||
|
return a.equal(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator!=(const pricing_record& a, const pricing_record& b) noexcept
|
||||||
|
{
|
||||||
|
return !a.equal(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // salvium_oracle
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
// Copyright (c) 2014-2022, The Monero Project
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
|
namespace serialization
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
inline constexpr bool use_container_varint() noexcept
|
||||||
|
{
|
||||||
|
return std::is_integral<T>::value && std::is_unsigned<T>::value && sizeof(T) > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Archive, class T>
|
||||||
|
typename std::enable_if<!use_container_varint<T>(), bool>::type
|
||||||
|
serialize_container_element(Archive& ar, T& e)
|
||||||
|
{
|
||||||
|
return do_serialize(ar, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Archive, typename T>
|
||||||
|
typename std::enable_if<use_container_varint<T>(), bool>::type
|
||||||
|
serialize_container_element(Archive& ar, T& e)
|
||||||
|
{
|
||||||
|
static constexpr const bool previously_varint = std::is_same<uint64_t, T>() || std::is_same<uint32_t, T>();
|
||||||
|
|
||||||
|
if (!previously_varint && ar.varint_bug_backward_compatibility_enabled() && !typename Archive::is_saving())
|
||||||
|
return do_serialize(ar, e);
|
||||||
|
ar.serialize_varint(e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename C>
|
||||||
|
void do_reserve(C &c, size_t N) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename C>
|
||||||
|
bool do_serialize_container(Archive<false> &ar, C &v)
|
||||||
|
{
|
||||||
|
size_t cnt;
|
||||||
|
ar.begin_array(cnt);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
v.clear();
|
||||||
|
|
||||||
|
// very basic sanity check
|
||||||
|
if (ar.remaining_bytes() < cnt) {
|
||||||
|
ar.set_fail();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
::serialization::detail::do_reserve(v, cnt);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < cnt; i++) {
|
||||||
|
if (i > 0)
|
||||||
|
ar.delimit_array();
|
||||||
|
typename C::value_type e;
|
||||||
|
if (!::serialization::detail::serialize_container_element(ar, e))
|
||||||
|
return false;
|
||||||
|
::serialization::detail::do_add(v, std::move(e));
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ar.end_array();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename C>
|
||||||
|
bool do_serialize_container(Archive<true> &ar, C &v)
|
||||||
|
{
|
||||||
|
size_t cnt = v.size();
|
||||||
|
ar.begin_array(cnt);
|
||||||
|
for (auto i = v.begin(); i != v.end(); ++i)
|
||||||
|
{
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
if (i != v.begin())
|
||||||
|
ar.delimit_array();
|
||||||
|
if(!::serialization::detail::serialize_container_element(ar, (typename C::value_type&)*i))
|
||||||
|
return false;
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ar.end_array();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
// Copyright (c) 2014-2022, The Monero Project
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <set>
|
||||||
|
#include "serialization.h"
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::vector<T> &v);
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::vector<T> &v);
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::deque<T> &v);
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::deque<T> &v);
|
||||||
|
|
||||||
|
template<typename K, typename V>
|
||||||
|
class serializable_unordered_map: public std::unordered_map<K, V>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename std::pair<K, V> value_type;
|
||||||
|
typename std::unordered_map<K, V> &parent() { return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_unordered_map<K, V> &v);
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_unordered_map<K, V> &v);
|
||||||
|
|
||||||
|
template<typename K, typename V>
|
||||||
|
class serializable_map: public std::map<K, V>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename std::pair<K, V> value_type;
|
||||||
|
typename std::map<K, V> &parent() { return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_map<K, V> &v);
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_map<K, V> &v);
|
||||||
|
|
||||||
|
template<typename K, typename V>
|
||||||
|
class serializable_unordered_multimap: public std::unordered_multimap<K, V>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename std::pair<K, V> value_type;
|
||||||
|
typename std::unordered_multimap<K, V> &parent() { return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_unordered_multimap<K, V> &v);
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_unordered_multimap<K, V> &v);
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::unordered_set<T> &v);
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::unordered_set<T> &v);
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::set<T> &v);
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::set<T> &v);
|
||||||
|
|
||||||
|
namespace serialization
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template <typename T> void do_reserve(std::vector<T> &c, size_t N) { c.reserve(N); }
|
||||||
|
template <typename T> void do_add(std::vector<T> &c, T &&e) { c.emplace_back(std::forward<T>(e)); }
|
||||||
|
|
||||||
|
template <typename T> void do_add(std::deque<T> &c, T &&e) { c.emplace_back(std::forward<T>(e)); }
|
||||||
|
|
||||||
|
template <typename K, typename V> void do_add(serializable_unordered_map<K, V> &c, std::pair<K, V> &&e) { c.insert(std::forward<std::pair<K, V>>(e)); }
|
||||||
|
|
||||||
|
template <typename K, typename V> void do_add(serializable_map<K, V> &c, std::pair<K, V> &&e) { c.insert(std::forward<std::pair<K, V>>(e)); }
|
||||||
|
|
||||||
|
template <typename K, typename V> void do_add(serializable_unordered_multimap<K, V> &c, std::pair<K, V> &&e) { c.insert(std::forward<std::pair<K, V>>(e)); }
|
||||||
|
|
||||||
|
template <typename T> void do_add(std::unordered_set<T> &c, T &&e) { c.insert(std::forward<T>(e)); }
|
||||||
|
|
||||||
|
template <typename T> void do_add(std::set<T> &c, T &&e) { c.insert(std::forward<T>(e)); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "container.h"
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::vector<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::vector<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::deque<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::deque<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_unordered_map<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_unordered_map<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_map<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_map<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<false> &ar, serializable_unordered_multimap<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, typename K, typename V> bool do_serialize(Archive<true> &ar, serializable_unordered_multimap<K, V> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::unordered_set<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::unordered_set<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<false> &ar, std::set<T> &v) { return do_serialize_container(ar, v); }
|
||||||
|
template <template <bool> class Archive, class T> bool do_serialize(Archive<true> &ar, std::set<T> &v) { return do_serialize_container(ar, v); }
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
// Copyright (c) 2019, Haven Protocol
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "serialization.h"
|
||||||
|
#include "salvium_oracle/pricing_record.h"
|
||||||
|
#include "cryptonote_config.h"
|
||||||
|
|
||||||
|
// read
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<false> &ar, salvium_oracle::supply_data &sd, uint8_t version)
|
||||||
|
{
|
||||||
|
ar.serialize_varint(sd.sal);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(sd.vsd);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<true> &ar, salvium_oracle::supply_data &sd, uint8_t version)
|
||||||
|
{
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(sd.sal);
|
||||||
|
ar.serialize_varint(sd.vsd);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<false> &ar, salvium_oracle::asset_data &ad, uint8_t version)
|
||||||
|
{
|
||||||
|
ar.serialize_string(ad.asset_type);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(ad.spot_price);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(ad.ma_price);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<true> &ar, salvium_oracle::asset_data &ad, uint8_t version)
|
||||||
|
{
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_string(ad.asset_type);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(ad.spot_price);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(ad.ma_price);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<false> &ar, salvium_oracle::pricing_record &pr, uint8_t version)
|
||||||
|
{
|
||||||
|
// very basic sanity checks
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.pr_version);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.height);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
if (!do_serialize(ar, pr.supply, version))
|
||||||
|
return false;
|
||||||
|
/*
|
||||||
|
// The next line should never do anything, but better safe than sorry
|
||||||
|
pr.asset_data.empty();
|
||||||
|
size_t asset_count;
|
||||||
|
ar.begin_array(asset_count);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
for (size_t idx=0; idx<asset_count; idx++) {
|
||||||
|
if (idx > 0) ar.delimit_array();
|
||||||
|
asset_data ad;
|
||||||
|
if (!do_serialize(ar, ad, version))
|
||||||
|
return false;
|
||||||
|
pr.asset_data.emplace_back(ad);
|
||||||
|
}
|
||||||
|
ar.end_array();
|
||||||
|
*/
|
||||||
|
if (!do_serialize_container(ar, pr.assets))
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.timestamp);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
if (!do_serialize_container(ar, pr.signature))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<true> &ar, salvium_oracle::pricing_record &pr, uint8_t version)
|
||||||
|
{
|
||||||
|
// very basic sanity checks
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.pr_version);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.height);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
if (!do_serialize(ar, pr.supply, version))
|
||||||
|
return false;
|
||||||
|
if (!do_serialize_container(ar, pr.assets))
|
||||||
|
return false;
|
||||||
|
ar.serialize_varint(pr.timestamp);
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
pr.signature.empty();
|
||||||
|
if (!do_serialize_container(ar, pr.signature))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//BLOB_SERIALIZER(salvium_oracle::supply_data);
|
||||||
|
//BLOB_SERIALIZER(salvium_oracle::asset_data);
|
||||||
|
//BLOB_SERIALIZER(salvium_oracle::pricing_record);
|
||||||
@@ -40,7 +40,33 @@
|
|||||||
template <template <bool> class Archive>
|
template <template <bool> class Archive>
|
||||||
bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record &pr, uint8_t version)
|
bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record &pr, uint8_t version)
|
||||||
{
|
{
|
||||||
if (version < 3)
|
if (version >= 4)
|
||||||
|
{
|
||||||
|
// very basic sanity check
|
||||||
|
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), "");
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (version >= 3)
|
||||||
|
{
|
||||||
|
// very basic sanity check
|
||||||
|
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record_v2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
zephyr_oracle::pricing_record_v2 pr_v2;
|
||||||
|
ar.serialize_blob(&pr_v2, sizeof(zephyr_oracle::pricing_record_v2), "");
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!pr_v2.write_to_pr(pr))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// very basic sanity check
|
// very basic sanity check
|
||||||
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record_v1)) {
|
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record_v1)) {
|
||||||
@@ -55,17 +81,6 @@ bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record &pr, uint8_t
|
|||||||
if (!pr_v1.write_to_pr(pr))
|
if (!pr_v1.write_to_pr(pr))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// very basic sanity check
|
|
||||||
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), "");
|
|
||||||
if (!ar.good())
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -76,17 +91,24 @@ bool do_serialize(Archive<true> &ar, zephyr_oracle::pricing_record &pr, uint8_t
|
|||||||
{
|
{
|
||||||
ar.begin_string();
|
ar.begin_string();
|
||||||
|
|
||||||
if (version < 3)
|
if (version >= 4)
|
||||||
|
{
|
||||||
|
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), "");
|
||||||
|
}
|
||||||
|
else if (version >= 3)
|
||||||
|
{
|
||||||
|
zephyr_oracle::pricing_record_v2 pr_v2;
|
||||||
|
if (!pr_v2.read_from_pr(pr))
|
||||||
|
return false;
|
||||||
|
ar.serialize_blob(&pr_v2, sizeof(zephyr_oracle::pricing_record_v2), "");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
zephyr_oracle::pricing_record_v1 pr_v1;
|
zephyr_oracle::pricing_record_v1 pr_v1;
|
||||||
if (!pr_v1.read_from_pr(pr))
|
if (!pr_v1.read_from_pr(pr))
|
||||||
return false;
|
return false;
|
||||||
ar.serialize_blob(&pr_v1, sizeof(zephyr_oracle::pricing_record_v1), "");
|
ar.serialize_blob(&pr_v1, sizeof(zephyr_oracle::pricing_record_v1), "");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ar.good())
|
if (!ar.good())
|
||||||
return false;
|
return false;
|
||||||
@@ -122,5 +144,34 @@ bool do_serialize(Archive<true> &ar, zephyr_oracle::pricing_record_v1 &pr, uint8
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record_v2 &pr, uint8_t version)
|
||||||
|
{
|
||||||
|
// very basic sanity check
|
||||||
|
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record_v2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record_v2), "");
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<true> &ar, zephyr_oracle::pricing_record_v2 &pr, uint8_t version)
|
||||||
|
{
|
||||||
|
ar.begin_string();
|
||||||
|
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record_v2), "");
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.end_string();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
BLOB_SERIALIZER(zephyr_oracle::pricing_record);
|
BLOB_SERIALIZER(zephyr_oracle::pricing_record);
|
||||||
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v1);
|
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v1);
|
||||||
|
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v2);
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ namespace zephyr_oracle
|
|||||||
uint64_t stable_ma;
|
uint64_t stable_ma;
|
||||||
uint64_t reserve;
|
uint64_t reserve;
|
||||||
uint64_t reserve_ma;
|
uint64_t reserve_ma;
|
||||||
|
uint64_t reserve_ratio;
|
||||||
|
uint64_t reserve_ratio_ma;
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
std::string signature;
|
std::string signature;
|
||||||
|
|
||||||
@@ -56,6 +58,8 @@ namespace zephyr_oracle
|
|||||||
KV_SERIALIZE(stable_ma)
|
KV_SERIALIZE(stable_ma)
|
||||||
KV_SERIALIZE(reserve)
|
KV_SERIALIZE(reserve)
|
||||||
KV_SERIALIZE(reserve_ma)
|
KV_SERIALIZE(reserve_ma)
|
||||||
|
KV_SERIALIZE(reserve_ratio)
|
||||||
|
KV_SERIALIZE(reserve_ratio_ma)
|
||||||
KV_SERIALIZE(timestamp)
|
KV_SERIALIZE(timestamp)
|
||||||
KV_SERIALIZE(signature)
|
KV_SERIALIZE(signature)
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
@@ -69,6 +73,8 @@ namespace zephyr_oracle
|
|||||||
, stable_ma(0)
|
, stable_ma(0)
|
||||||
, reserve(0)
|
, reserve(0)
|
||||||
, reserve_ma(0)
|
, reserve_ma(0)
|
||||||
|
, reserve_ratio(0)
|
||||||
|
, reserve_ratio_ma(0)
|
||||||
, timestamp(0)
|
, timestamp(0)
|
||||||
{
|
{
|
||||||
std::memset(signature, 0, sizeof(signature));
|
std::memset(signature, 0, sizeof(signature));
|
||||||
@@ -86,6 +92,8 @@ namespace zephyr_oracle
|
|||||||
stable_ma = in.stable_ma;
|
stable_ma = in.stable_ma;
|
||||||
reserve = in.reserve;
|
reserve = in.reserve;
|
||||||
reserve_ma = in.reserve_ma;
|
reserve_ma = in.reserve_ma;
|
||||||
|
reserve_ratio = in.reserve_ratio;
|
||||||
|
reserve_ratio_ma = in.reserve_ratio_ma;
|
||||||
timestamp = in.timestamp;
|
timestamp = in.timestamp;
|
||||||
for (unsigned int i = 0; i < in.signature.length(); i += 2) {
|
for (unsigned int i = 0; i < in.signature.length(); i += 2) {
|
||||||
std::string byteString = in.signature.substr(i, 2);
|
std::string byteString = in.signature.substr(i, 2);
|
||||||
@@ -106,7 +114,7 @@ namespace zephyr_oracle
|
|||||||
ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature[i]);
|
ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature[i]);
|
||||||
sig_hex += ss.str();
|
sig_hex += ss.str();
|
||||||
}
|
}
|
||||||
const pr_serialized out{spot,moving_average,stable,stable_ma,reserve,reserve_ma,timestamp,sig_hex};
|
const pr_serialized out{spot,moving_average,stable,stable_ma,reserve,reserve_ma,reserve_ratio,reserve_ratio_ma,timestamp,sig_hex};
|
||||||
return out.store(dest, hparent);
|
return out.store(dest, hparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +125,8 @@ namespace zephyr_oracle
|
|||||||
, stable_ma(orig.stable_ma)
|
, stable_ma(orig.stable_ma)
|
||||||
, reserve(orig.reserve)
|
, reserve(orig.reserve)
|
||||||
, reserve_ma(orig.reserve_ma)
|
, reserve_ma(orig.reserve_ma)
|
||||||
|
, reserve_ratio(orig.reserve_ratio)
|
||||||
|
, reserve_ratio_ma(orig.reserve_ratio_ma)
|
||||||
, timestamp(orig.timestamp)
|
, timestamp(orig.timestamp)
|
||||||
{
|
{
|
||||||
std::memcpy(signature, orig.signature, sizeof(signature));
|
std::memcpy(signature, orig.signature, sizeof(signature));
|
||||||
@@ -130,6 +140,8 @@ namespace zephyr_oracle
|
|||||||
stable_ma = orig.stable_ma;
|
stable_ma = orig.stable_ma;
|
||||||
reserve = orig.reserve;
|
reserve = orig.reserve;
|
||||||
reserve_ma = orig.reserve_ma;
|
reserve_ma = orig.reserve_ma;
|
||||||
|
reserve_ratio = orig.reserve_ratio;
|
||||||
|
reserve_ratio_ma = orig.reserve_ratio_ma;
|
||||||
timestamp = orig.timestamp;
|
timestamp = orig.timestamp;
|
||||||
::memcpy(signature, orig.signature, sizeof(signature));
|
::memcpy(signature, orig.signature, sizeof(signature));
|
||||||
return *this;
|
return *this;
|
||||||
@@ -143,6 +155,8 @@ namespace zephyr_oracle
|
|||||||
(stable_ma == other.stable_ma) &&
|
(stable_ma == other.stable_ma) &&
|
||||||
(reserve == other.reserve) &&
|
(reserve == other.reserve) &&
|
||||||
(reserve_ma == other.reserve_ma) &&
|
(reserve_ma == other.reserve_ma) &&
|
||||||
|
(reserve_ratio == other.reserve_ratio) &&
|
||||||
|
(reserve_ratio_ma == other.reserve_ratio_ma) &&
|
||||||
(timestamp == other.timestamp) &&
|
(timestamp == other.timestamp) &&
|
||||||
!::memcmp(signature, other.signature, sizeof(signature)));
|
!::memcmp(signature, other.signature, sizeof(signature)));
|
||||||
}
|
}
|
||||||
@@ -153,7 +167,7 @@ namespace zephyr_oracle
|
|||||||
return (*this).equal(empty_pr);
|
return (*this).equal(empty_pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pricing_record::verifySignature(const std::string& public_key) const
|
bool pricing_record::verifySignature(const std::string& public_key, const uint8_t hf_version) const
|
||||||
{
|
{
|
||||||
CHECK_AND_ASSERT_THROW_MES(!public_key.empty(), "Pricing record verification failed. NULL public key. PK Size: " << public_key.size()); // TODO: is this necessary or the one below already covers this case, meannin it will produce empty pubkey?
|
CHECK_AND_ASSERT_THROW_MES(!public_key.empty(), "Pricing record verification failed. NULL public key. PK Size: " << public_key.size()); // TODO: is this necessary or the one below already covers this case, meannin it will produce empty pubkey?
|
||||||
|
|
||||||
@@ -178,7 +192,9 @@ namespace zephyr_oracle
|
|||||||
// Build the JSON string, so that we can verify the signature
|
// Build the JSON string, so that we can verify the signature
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "{\"spot\":" << spot;
|
oss << "{\"spot\":" << spot;
|
||||||
oss << ",\"moving_average\":" << moving_average;
|
if (hf_version <= 4) {
|
||||||
|
oss << ",\"moving_average\":" << moving_average;
|
||||||
|
}
|
||||||
oss << ",\"timestamp\":" << timestamp;
|
oss << ",\"timestamp\":" << timestamp;
|
||||||
oss << "}";
|
oss << "}";
|
||||||
std::string message = oss.str();
|
std::string message = oss.str();
|
||||||
@@ -210,9 +226,24 @@ namespace zephyr_oracle
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pricing_record::has_missing_rates() const noexcept
|
bool pricing_record::has_missing_rates(const uint8_t hf_version) const noexcept
|
||||||
{
|
{
|
||||||
return (spot == 0) || (moving_average == 0) || (stable == 0) || (stable_ma == 0) || (reserve == 0) || (reserve_ma == 0);
|
bool missing_rates = (spot == 0) || (moving_average == 0) || (stable == 0) || (stable_ma == 0) || (reserve == 0) || (reserve_ma == 0);
|
||||||
|
if (hf_version <= 3) {
|
||||||
|
return missing_rates;
|
||||||
|
} else if (hf_version <= 4) {
|
||||||
|
return missing_rates || (reserve_ratio == 0);
|
||||||
|
}
|
||||||
|
return missing_rates || (reserve_ratio == 0) || (reserve_ratio_ma == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::has_essential_rates(const uint8_t hf_version) const noexcept
|
||||||
|
{
|
||||||
|
bool essential_rates = (spot != 0) && (stable != 0) && (reserve != 0);
|
||||||
|
if (hf_version <= 3) {
|
||||||
|
return essential_rates;
|
||||||
|
}
|
||||||
|
return essential_rates && (reserve_ratio != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// overload for pr validation for block
|
// overload for pr validation for block
|
||||||
@@ -226,9 +257,11 @@ namespace zephyr_oracle
|
|||||||
if (this->empty())
|
if (this->empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (this->has_missing_rates()) {
|
if (this->has_missing_rates(hf_version)) {
|
||||||
LOG_ERROR("Pricing record has missing rates.");
|
if (hf_version < 4 || !this->has_essential_rates(hf_version)) {
|
||||||
return false;
|
LOG_ERROR("Pricing record has missing rates.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const MAINNET_ORACLE_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n"
|
std::string const MAINNET_ORACLE_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n"
|
||||||
@@ -236,7 +269,7 @@ namespace zephyr_oracle
|
|||||||
"edsUmhQeYwBkelAaFyxhX4ZotP+b/cFr2mX5iuND1znEnMZkyg+YmtkCAwEAAQ==\n"
|
"edsUmhQeYwBkelAaFyxhX4ZotP+b/cFr2mX5iuND1znEnMZkyg+YmtkCAwEAAQ==\n"
|
||||||
"-----END PUBLIC KEY-----\n";
|
"-----END PUBLIC KEY-----\n";
|
||||||
|
|
||||||
if (!verifySignature(MAINNET_ORACLE_PUBLIC_KEY)) {
|
if (!verifySignature(MAINNET_ORACLE_PUBLIC_KEY, hf_version)) {
|
||||||
LOG_ERROR("Invalid pricing record signature.");
|
LOG_ERROR("Invalid pricing record signature.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,16 @@ namespace zephyr_oracle
|
|||||||
uint64_t zEPHRSV;
|
uint64_t zEPHRSV;
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
};
|
};
|
||||||
|
POD_CLASS pricing_record_pre_v2 {
|
||||||
|
uint64_t spot;
|
||||||
|
uint64_t moving_average;
|
||||||
|
uint64_t stable;
|
||||||
|
uint64_t stable_ma;
|
||||||
|
uint64_t reserve;
|
||||||
|
uint64_t reserve_ma;
|
||||||
|
uint64_t timestamp;
|
||||||
|
unsigned char signature[64];
|
||||||
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
class pricing_record
|
class pricing_record
|
||||||
{
|
{
|
||||||
@@ -76,6 +86,8 @@ namespace zephyr_oracle
|
|||||||
uint64_t stable_ma;
|
uint64_t stable_ma;
|
||||||
uint64_t reserve;
|
uint64_t reserve;
|
||||||
uint64_t reserve_ma;
|
uint64_t reserve_ma;
|
||||||
|
uint64_t reserve_ratio;
|
||||||
|
uint64_t reserve_ratio_ma;
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
unsigned char signature[64];
|
unsigned char signature[64];
|
||||||
|
|
||||||
@@ -89,8 +101,9 @@ namespace zephyr_oracle
|
|||||||
~pricing_record() = default;
|
~pricing_record() = default;
|
||||||
bool equal(const pricing_record& other) const noexcept;
|
bool equal(const pricing_record& other) const noexcept;
|
||||||
bool empty() const noexcept;
|
bool empty() const noexcept;
|
||||||
bool verifySignature(const std::string& public_key) const;
|
bool verifySignature(const std::string& public_key, const uint8_t hf_version) const;
|
||||||
bool has_missing_rates() const noexcept;
|
bool has_missing_rates(const uint8_t hf_version) const noexcept;
|
||||||
|
bool has_essential_rates(const uint8_t hf_version) const noexcept;
|
||||||
bool valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const;
|
bool valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const;
|
||||||
|
|
||||||
pricing_record& operator=(const pricing_record& orig) noexcept;
|
pricing_record& operator=(const pricing_record& orig) noexcept;
|
||||||
@@ -137,4 +150,46 @@ namespace zephyr_oracle
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class pricing_record_v2
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
uint64_t spot;
|
||||||
|
uint64_t moving_average;
|
||||||
|
uint64_t stable;
|
||||||
|
uint64_t stable_ma;
|
||||||
|
uint64_t reserve;
|
||||||
|
uint64_t reserve_ma;
|
||||||
|
uint64_t timestamp;
|
||||||
|
unsigned char signature[64];
|
||||||
|
|
||||||
|
bool write_to_pr(zephyr_oracle::pricing_record &pr)
|
||||||
|
{
|
||||||
|
pr.spot = spot;
|
||||||
|
pr.moving_average = moving_average;
|
||||||
|
pr.stable = stable;
|
||||||
|
pr.stable_ma = stable_ma;
|
||||||
|
pr.reserve = reserve;
|
||||||
|
pr.reserve_ma = reserve_ma;
|
||||||
|
pr.reserve_ratio = 0;
|
||||||
|
pr.reserve_ratio_ma = 0;
|
||||||
|
pr.timestamp = timestamp;
|
||||||
|
std::memcpy(pr.signature, signature, sizeof(pr.signature));
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool read_from_pr(zephyr_oracle::pricing_record &pr)
|
||||||
|
{
|
||||||
|
spot = pr.spot;
|
||||||
|
moving_average = pr.moving_average;
|
||||||
|
stable = pr.stable;
|
||||||
|
stable_ma = pr.stable_ma;
|
||||||
|
reserve = pr.reserve;
|
||||||
|
reserve_ma = pr.reserve_ma;
|
||||||
|
timestamp = pr.timestamp;
|
||||||
|
std::memcpy(signature, pr.signature, sizeof(signature));
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
} // oracle
|
} // oracle
|
||||||
|
|||||||
Reference in New Issue
Block a user