2015-05-27 12:08:46 +00:00
|
|
|
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
|
2014-08-13 10:38:35 +00:00
|
|
|
//
|
|
|
|
// This file is part of Bytecoin.
|
|
|
|
//
|
|
|
|
// Bytecoin is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Bytecoin is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "Chaingen.h"
|
2014-08-13 10:51:37 +00:00
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
2014-08-13 10:51:37 +00:00
|
|
|
#include <stdint.h>
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2014-08-13 10:51:37 +00:00
|
|
|
#include <boost/archive/binary_oarchive.hpp>
|
|
|
|
#include <boost/archive/binary_iarchive.hpp>
|
|
|
|
#include <boost/program_options.hpp>
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "Common/CommandLine.h"
|
|
|
|
#include "CryptoNoteCore/CryptoNoteBasic.h"
|
|
|
|
#include "CryptoNoteCore/CryptoNoteBasicImpl.h"
|
|
|
|
#include "CryptoNoteCore/CryptoNoteFormatUtils.h"
|
|
|
|
#include "CryptoNoteCore/CryptoNoteTools.h"
|
|
|
|
#include "CryptoNoteCore/Core.h"
|
|
|
|
#include "CryptoNoteCore/Currency.h"
|
|
|
|
#include "CryptoNoteCore/UpgradeDetector.h"
|
|
|
|
|
|
|
|
//#include "AccountBoostSerialization.h"
|
|
|
|
//#include "cryptonote_boost_serialization.h"
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2015-05-27 12:08:46 +00:00
|
|
|
using namespace CryptoNote;
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
struct output_index {
|
2015-05-27 12:08:46 +00:00
|
|
|
const CryptoNote::TransactionOutputTarget out;
|
2014-03-03 22:07:58 +00:00
|
|
|
uint64_t amount;
|
|
|
|
size_t blk_height; // block height
|
|
|
|
size_t tx_no; // index of transaction in block
|
|
|
|
size_t out_no; // index of out in transaction
|
2015-07-30 15:22:07 +00:00
|
|
|
uint32_t idx;
|
2014-03-03 22:07:58 +00:00
|
|
|
bool spent;
|
2015-05-27 12:08:46 +00:00
|
|
|
const CryptoNote::Block *p_blk;
|
|
|
|
const CryptoNote::Transaction *p_tx;
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
output_index(const CryptoNote::TransactionOutputTarget &_out, uint64_t _a, size_t _h, size_t tno, size_t ono, const CryptoNote::Block *_pb, const CryptoNote::Transaction *_pt)
|
2014-03-03 22:07:58 +00:00
|
|
|
: out(_out), amount(_a), blk_height(_h), tx_no(tno), out_no(ono), idx(0), spent(false), p_blk(_pb), p_tx(_pt) { }
|
|
|
|
|
|
|
|
output_index(const output_index &other)
|
|
|
|
: out(other.out), amount(other.amount), blk_height(other.blk_height), tx_no(other.tx_no), out_no(other.out_no), idx(other.idx), spent(other.spent), p_blk(other.p_blk), p_tx(other.p_tx) { }
|
|
|
|
|
|
|
|
const std::string toString() const {
|
|
|
|
std::stringstream ss;
|
|
|
|
|
|
|
|
ss << "output_index{blk_height=" << blk_height
|
|
|
|
<< " tx_no=" << tx_no
|
|
|
|
<< " out_no=" << out_no
|
|
|
|
<< " amount=" << amount
|
|
|
|
<< " idx=" << idx
|
|
|
|
<< " spent=" << spent
|
|
|
|
<< "}";
|
|
|
|
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
output_index& operator=(const output_index& other)
|
|
|
|
{
|
|
|
|
new(this) output_index(other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<uint64_t, std::vector<size_t> > map_output_t;
|
|
|
|
typedef std::map<uint64_t, std::vector<output_index> > map_output_idx_t;
|
|
|
|
typedef pair<uint64_t, size_t> outloc_t;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2015-07-30 15:22:07 +00:00
|
|
|
uint64_t get_inputs_amount(const vector<TransactionSourceEntry> &s)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
|
|
|
uint64_t r = 0;
|
2015-07-30 15:22:07 +00:00
|
|
|
BOOST_FOREACH(const TransactionSourceEntry &e, s)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
|
|
|
r += e.amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
bool init_output_indices(map_output_idx_t& outs, std::map<uint64_t, std::vector<size_t> >& outs_mine, const std::vector<CryptoNote::Block>& blockchain, const map_hash2tx_t& mtx, const CryptoNote::AccountBase& from) {
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2014-08-13 10:51:37 +00:00
|
|
|
BOOST_FOREACH (const Block& blk, blockchain) {
|
|
|
|
vector<const Transaction*> vtx;
|
2015-07-30 15:22:07 +00:00
|
|
|
vtx.push_back(&blk.baseTransaction);
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
for (const Crypto::Hash& h : blk.transactionHashes) {
|
2014-03-03 22:07:58 +00:00
|
|
|
const map_hash2tx_t::const_iterator cit = mtx.find(h);
|
|
|
|
if (mtx.end() == cit)
|
|
|
|
throw std::runtime_error("block contains an unknown tx hash");
|
|
|
|
|
|
|
|
vtx.push_back(cit->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
//vtx.insert(vtx.end(), blk.);
|
|
|
|
// TODO: add all other txes
|
|
|
|
for (size_t i = 0; i < vtx.size(); i++) {
|
2014-08-13 10:51:37 +00:00
|
|
|
const Transaction &tx = *vtx[i];
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2014-08-13 10:51:37 +00:00
|
|
|
size_t keyIndex = 0;
|
2015-07-30 15:22:07 +00:00
|
|
|
for (size_t j = 0; j < tx.outputs.size(); ++j) {
|
|
|
|
const TransactionOutput &out = tx.outputs[j];
|
|
|
|
if (out.target.type() == typeid(KeyOutput)) {
|
|
|
|
output_index oi(out.target, out.amount, boost::get<BaseInput>(*blk.baseTransaction.inputs.begin()).blockIndex, i, j, &blk, vtx[i]);
|
2014-08-13 10:51:37 +00:00
|
|
|
outs[out.amount].push_back(oi);
|
2015-07-30 15:22:07 +00:00
|
|
|
uint32_t tx_global_idx = static_cast<uint32_t>(outs[out.amount].size() - 1);
|
2014-08-13 10:51:37 +00:00
|
|
|
outs[out.amount][tx_global_idx].idx = tx_global_idx;
|
|
|
|
// Is out to me?
|
2015-07-30 15:22:07 +00:00
|
|
|
if (is_out_to_acc(from.getAccountKeys(), boost::get<KeyOutput>(out.target), getTransactionPublicKeyFromExtra(tx.extra), keyIndex)) {
|
2014-08-13 10:51:37 +00:00
|
|
|
outs_mine[out.amount].push_back(tx_global_idx);
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
2014-08-13 10:51:37 +00:00
|
|
|
|
|
|
|
++keyIndex;
|
2015-07-30 15:22:07 +00:00
|
|
|
} else if (out.target.type() == typeid(MultisignatureOutput)) {
|
|
|
|
keyIndex += boost::get<MultisignatureOutput>(out.target).keys.size();
|
2014-08-13 10:51:37 +00:00
|
|
|
}
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
bool init_spent_output_indices(map_output_idx_t& outs, map_output_t& outs_mine, const std::vector<CryptoNote::Block>& blockchain, const map_hash2tx_t& mtx, const CryptoNote::AccountBase& from) {
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2014-08-13 10:51:37 +00:00
|
|
|
for (const map_output_t::value_type& o: outs_mine) {
|
2014-03-03 22:07:58 +00:00
|
|
|
for (size_t i = 0; i < o.second.size(); ++i) {
|
|
|
|
output_index &oi = outs[o.first][o.second[i]];
|
|
|
|
|
|
|
|
// construct key image for this output
|
2015-07-30 15:22:07 +00:00
|
|
|
Crypto::KeyImage img;
|
2014-08-13 10:51:37 +00:00
|
|
|
KeyPair in_ephemeral;
|
2015-07-30 15:22:07 +00:00
|
|
|
generate_key_image_helper(from.getAccountKeys(), getTransactionPublicKeyFromExtra(oi.p_tx->extra), oi.out_no, in_ephemeral, img);
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
// lookup for this key image in the events vector
|
2014-08-13 10:51:37 +00:00
|
|
|
for (auto& tx_pair : mtx) {
|
|
|
|
const Transaction& tx = *tx_pair.second;
|
2015-07-30 15:22:07 +00:00
|
|
|
for (const auto& in : tx.inputs) {
|
|
|
|
if (in.type() == typeid(KeyInput)) {
|
|
|
|
const KeyInput &itk = boost::get<KeyInput>(in);
|
2014-08-13 10:51:37 +00:00
|
|
|
if (itk.keyImage == img) {
|
2014-03-03 22:07:58 +00:00
|
|
|
oi.spent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
bool fill_output_entries(std::vector<output_index>& out_indices, size_t sender_out, size_t nmix, size_t& real_entry_idx, std::vector<TransactionSourceEntry::OutputEntry>& output_entries)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
|
|
|
if (out_indices.size() <= nmix)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool sender_out_found = false;
|
|
|
|
size_t rest = nmix;
|
|
|
|
for (size_t i = 0; i < out_indices.size() && (0 < rest || !sender_out_found); ++i)
|
|
|
|
{
|
|
|
|
const output_index& oi = out_indices[i];
|
|
|
|
if (oi.spent)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool append = false;
|
|
|
|
if (i == sender_out)
|
|
|
|
{
|
|
|
|
append = true;
|
|
|
|
sender_out_found = true;
|
|
|
|
real_entry_idx = output_entries.size();
|
|
|
|
}
|
|
|
|
else if (0 < rest)
|
|
|
|
{
|
|
|
|
--rest;
|
|
|
|
append = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (append)
|
|
|
|
{
|
2015-07-30 15:22:07 +00:00
|
|
|
const KeyOutput& otk = boost::get<KeyOutput>(oi.out);
|
|
|
|
output_entries.push_back(TransactionSourceEntry::OutputEntry(oi.idx, otk.key));
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0 == rest && sender_out_found;
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
bool fill_tx_sources(std::vector<TransactionSourceEntry>& sources, const std::vector<test_event_entry>& events,
|
|
|
|
const Block& blk_head, const CryptoNote::AccountBase& from, uint64_t amount, size_t nmix)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
|
|
|
map_output_idx_t outs;
|
|
|
|
map_output_t outs_mine;
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
std::vector<CryptoNote::Block> blockchain;
|
2014-03-03 22:07:58 +00:00
|
|
|
map_hash2tx_t mtx;
|
|
|
|
if (!find_block_chain(events, blockchain, mtx, get_block_hash(blk_head)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!init_output_indices(outs, outs_mine, blockchain, mtx, from))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!init_spent_output_indices(outs, outs_mine, blockchain, mtx, from))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Iterate in reverse is more efficiency
|
|
|
|
uint64_t sources_amount = 0;
|
|
|
|
bool sources_found = false;
|
|
|
|
BOOST_REVERSE_FOREACH(const map_output_t::value_type o, outs_mine)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < o.second.size() && !sources_found; ++i)
|
|
|
|
{
|
|
|
|
size_t sender_out = o.second[i];
|
|
|
|
const output_index& oi = outs[o.first][sender_out];
|
|
|
|
if (oi.spent)
|
|
|
|
continue;
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
CryptoNote::TransactionSourceEntry ts;
|
2014-03-03 22:07:58 +00:00
|
|
|
ts.amount = oi.amount;
|
2015-07-30 15:22:07 +00:00
|
|
|
ts.realOutputIndexInTransaction = oi.out_no;
|
|
|
|
ts.realTransactionPublicKey = getTransactionPublicKeyFromExtra(oi.p_tx->extra); // incoming tx public key
|
2014-04-29 16:26:45 +00:00
|
|
|
size_t realOutput;
|
|
|
|
if (!fill_output_entries(outs[o.first], sender_out, nmix, realOutput, ts.outputs))
|
2014-03-03 22:07:58 +00:00
|
|
|
continue;
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
ts.realOutput = realOutput;
|
2014-04-29 16:26:45 +00:00
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
sources.push_back(ts);
|
|
|
|
|
|
|
|
sources_amount += ts.amount;
|
|
|
|
sources_found = amount <= sources_amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sources_found)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sources_found;
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
bool fill_tx_destination(TransactionDestinationEntry &de, const CryptoNote::AccountBase &to, uint64_t amount) {
|
|
|
|
de.addr = to.getAccountKeys().address;
|
2014-03-03 22:07:58 +00:00
|
|
|
de.amount = amount;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-13 10:51:37 +00:00
|
|
|
void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const Block& blk_head,
|
2015-07-30 15:22:07 +00:00
|
|
|
const CryptoNote::AccountBase& from, const CryptoNote::AccountBase& to,
|
|
|
|
uint64_t amount, uint64_t fee, size_t nmix, std::vector<TransactionSourceEntry>& sources,
|
|
|
|
std::vector<TransactionDestinationEntry>& destinations)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
|
|
|
sources.clear();
|
|
|
|
destinations.clear();
|
|
|
|
|
|
|
|
if (!fill_tx_sources(sources, events, blk_head, from, amount + fee, nmix))
|
|
|
|
throw std::runtime_error("couldn't fill transaction sources");
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
TransactionDestinationEntry de;
|
2014-03-03 22:07:58 +00:00
|
|
|
if (!fill_tx_destination(de, to, amount))
|
|
|
|
throw std::runtime_error("couldn't fill transaction destination");
|
|
|
|
destinations.push_back(de);
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
TransactionDestinationEntry de_change;
|
2014-03-03 22:07:58 +00:00
|
|
|
uint64_t cache_back = get_inputs_amount(sources) - (amount + fee);
|
|
|
|
if (0 < cache_back)
|
|
|
|
{
|
|
|
|
if (!fill_tx_destination(de_change, from, cache_back))
|
|
|
|
throw std::runtime_error("couldn't fill transaction cache back destination");
|
|
|
|
destinations.push_back(de_change);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
bool construct_tx_to_key(Logging::ILogger& logger, const std::vector<test_event_entry>& events, CryptoNote::Transaction& tx, const Block& blk_head,
|
2015-07-30 15:22:07 +00:00
|
|
|
const CryptoNote::AccountBase& from, const CryptoNote::AccountBase& to, uint64_t amount,
|
2014-03-03 22:07:58 +00:00
|
|
|
uint64_t fee, size_t nmix)
|
|
|
|
{
|
2015-07-30 15:22:07 +00:00
|
|
|
vector<TransactionSourceEntry> sources;
|
|
|
|
vector<TransactionDestinationEntry> destinations;
|
2014-03-03 22:07:58 +00:00
|
|
|
fill_tx_sources_and_destinations(events, blk_head, from, to, amount, fee, nmix, sources, destinations);
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
return constructTransaction(from.getAccountKeys(), sources, destinations, std::vector<uint8_t>(), tx, 0, logger);
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
Transaction construct_tx_with_fee(Logging::ILogger& logger, std::vector<test_event_entry>& events, const Block& blk_head,
|
2015-07-30 15:22:07 +00:00
|
|
|
const AccountBase& acc_from, const AccountBase& acc_to, uint64_t amount, uint64_t fee)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
2014-08-13 10:51:37 +00:00
|
|
|
Transaction tx;
|
2015-05-27 12:08:46 +00:00
|
|
|
construct_tx_to_key(logger, events, tx, blk_head, acc_from, acc_to, amount, fee, 0);
|
2014-03-03 22:07:58 +00:00
|
|
|
events.push_back(tx);
|
|
|
|
return tx;
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
uint64_t get_balance(const CryptoNote::AccountBase& addr, const std::vector<CryptoNote::Block>& blockchain, const map_hash2tx_t& mtx) {
|
2014-03-03 22:07:58 +00:00
|
|
|
uint64_t res = 0;
|
|
|
|
std::map<uint64_t, std::vector<output_index> > outs;
|
|
|
|
std::map<uint64_t, std::vector<size_t> > outs_mine;
|
|
|
|
|
|
|
|
map_hash2tx_t confirmed_txs;
|
|
|
|
get_confirmed_txs(blockchain, mtx, confirmed_txs);
|
|
|
|
|
|
|
|
if (!init_output_indices(outs, outs_mine, blockchain, confirmed_txs, addr))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!init_spent_output_indices(outs, outs_mine, blockchain, confirmed_txs, addr))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
BOOST_FOREACH (const map_output_t::value_type &o, outs_mine) {
|
|
|
|
for (size_t i = 0; i < o.second.size(); ++i) {
|
|
|
|
if (outs[o.first][o.second[i]].spent)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
res += outs[o.first][o.second[i]].amount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
void get_confirmed_txs(const std::vector<CryptoNote::Block>& blockchain, const map_hash2tx_t& mtx, map_hash2tx_t& confirmed_txs)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
2015-07-30 15:22:07 +00:00
|
|
|
std::unordered_set<Crypto::Hash> confirmed_hashes;
|
2014-08-13 10:51:37 +00:00
|
|
|
for (const Block& blk : blockchain)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
2015-07-30 15:22:07 +00:00
|
|
|
for (const Crypto::Hash& tx_hash : blk.transactionHashes)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
|
|
|
confirmed_hashes.insert(tx_hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FOREACH(const auto& tx_pair, mtx)
|
|
|
|
{
|
|
|
|
if (0 != confirmed_hashes.count(tx_pair.first))
|
|
|
|
{
|
|
|
|
confirmed_txs.insert(tx_pair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<CryptoNote::Block>& blockchain, map_hash2tx_t& mtx, const Crypto::Hash& head) {
|
|
|
|
std::unordered_map<Crypto::Hash, const Block*> block_index;
|
2014-03-03 22:07:58 +00:00
|
|
|
BOOST_FOREACH(const test_event_entry& ev, events)
|
|
|
|
{
|
2014-08-13 10:51:37 +00:00
|
|
|
if (typeid(Block) == ev.type())
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
2014-08-13 10:51:37 +00:00
|
|
|
const Block* blk = &boost::get<Block>(ev);
|
2014-03-03 22:07:58 +00:00
|
|
|
block_index[get_block_hash(*blk)] = blk;
|
|
|
|
}
|
2014-08-13 10:51:37 +00:00
|
|
|
else if (typeid(Transaction) == ev.type())
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
2014-08-13 10:51:37 +00:00
|
|
|
const Transaction& tx = boost::get<Transaction>(ev);
|
2015-07-30 15:22:07 +00:00
|
|
|
mtx[getObjectHash(tx)] = &tx;
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool b_success = false;
|
2015-07-30 15:22:07 +00:00
|
|
|
Crypto::Hash id = head;
|
2014-03-03 22:07:58 +00:00
|
|
|
for (auto it = block_index.find(id); block_index.end() != it; it = block_index.find(id))
|
|
|
|
{
|
|
|
|
blockchain.push_back(*it->second);
|
2015-07-30 15:22:07 +00:00
|
|
|
id = it->second->previousBlockHash;
|
|
|
|
if (NULL_HASH == id)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
|
|
|
b_success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reverse(blockchain.begin(), blockchain.end());
|
|
|
|
|
|
|
|
return b_success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
const CryptoNote::Currency& test_chain_unit_base::currency() const
|
2014-08-13 10:51:37 +00:00
|
|
|
{
|
|
|
|
return m_currency;
|
|
|
|
}
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
void test_chain_unit_base::register_callback(const std::string& cb_name, verify_callback cb)
|
|
|
|
{
|
|
|
|
m_callbacks[cb_name] = cb;
|
|
|
|
}
|
2014-08-13 10:51:37 +00:00
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
bool test_chain_unit_base::verify(const std::string& cb_name, CryptoNote::core& c, size_t ev_index, const std::vector<test_event_entry> &events)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
|
|
|
auto cb_it = m_callbacks.find(cb_name);
|
|
|
|
if(cb_it == m_callbacks.end())
|
|
|
|
{
|
|
|
|
LOG_ERROR("Failed to find callback " << cb_name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return cb_it->second(c, ev_index, events);
|
|
|
|
}
|