mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
9ea098413a
faec689bed7a5b66e2a7675853d10205b933cec8 txmempool: Make entry time type-safe (std::chrono) (MarcoFalke) faaa1f01daba94b021ca77515266a16d27f0364e util: Add count_seconds time helper (MarcoFalke) 1111170f2f0141084b5b4ed565b2f07eba48599a test: mempool entry time is persisted (MarcoFalke) Pull request description: This changes the type of the entry time of txs into the mempool from `int64_t` to `std::chrono::seconds`. The benefits: * Documents the type for developers * Type violations result in compile errors * After compilation, the two are equivalent (at no run time cost) ACKs for top commit: ajtowns: utACK faec689bed7a5b66e2a7675853d10205b933cec8 laanwj: ACK faec689bed7a5b66e2a7675853d10205b933cec8 Tree-SHA512: d958e058755d1a1d54cef536a8b30a11cc502b7df0d6ecf84a0ab1d38bc8105a67668a99cd5087a444f6de2421238111c5fca133cdf8e2e2273cb12cb6957845
85 lines
2.1 KiB
C++
85 lines
2.1 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_ADDRESSINDEX_H
|
|
#define BITCOIN_ADDRESSINDEX_H
|
|
|
|
#include <uint256.h>
|
|
#include <amount.h>
|
|
|
|
#include <chrono>
|
|
|
|
struct CMempoolAddressDelta
|
|
{
|
|
std::chrono::seconds time;
|
|
CAmount amount;
|
|
uint256 prevhash;
|
|
unsigned int prevout;
|
|
|
|
CMempoolAddressDelta(std::chrono::seconds t, CAmount a, uint256 hash, unsigned int out) {
|
|
time = t;
|
|
amount = a;
|
|
prevhash = hash;
|
|
prevout = out;
|
|
}
|
|
|
|
CMempoolAddressDelta(std::chrono::seconds t, CAmount a) {
|
|
time = t;
|
|
amount = a;
|
|
prevhash.SetNull();
|
|
prevout = 0;
|
|
}
|
|
};
|
|
|
|
struct CMempoolAddressDeltaKey
|
|
{
|
|
int type;
|
|
uint160 addressBytes;
|
|
uint256 txhash;
|
|
unsigned int index;
|
|
int spending;
|
|
|
|
CMempoolAddressDeltaKey(int addressType, uint160 addressHash, uint256 hash, unsigned int i, int s) {
|
|
type = addressType;
|
|
addressBytes = addressHash;
|
|
txhash = hash;
|
|
index = i;
|
|
spending = s;
|
|
}
|
|
|
|
CMempoolAddressDeltaKey(int addressType, uint160 addressHash) {
|
|
type = addressType;
|
|
addressBytes = addressHash;
|
|
txhash.SetNull();
|
|
index = 0;
|
|
spending = 0;
|
|
}
|
|
};
|
|
|
|
struct CMempoolAddressDeltaKeyCompare
|
|
{
|
|
bool operator()(const CMempoolAddressDeltaKey& a, const CMempoolAddressDeltaKey& b) const {
|
|
if (a.type == b.type) {
|
|
if (a.addressBytes == b.addressBytes) {
|
|
if (a.txhash == b.txhash) {
|
|
if (a.index == b.index) {
|
|
return a.spending < b.spending;
|
|
} else {
|
|
return a.index < b.index;
|
|
}
|
|
} else {
|
|
return a.txhash < b.txhash;
|
|
}
|
|
} else {
|
|
return a.addressBytes < b.addressBytes;
|
|
}
|
|
} else {
|
|
return a.type < b.type;
|
|
}
|
|
}
|
|
};
|
|
|
|
#endif // BITCOIN_ADDRESSINDEX_H
|