mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-20 16:48:40 +02:00
start cnBlockToBlock(), cnTransactionToTx() utilities;
onNewBlock(uint64_t) only (no block info provided by w2);
This commit is contained in:
+3
-3
@@ -228,11 +228,11 @@ set_target_properties(version PROPERTIES IMPORTED_LOCATION
|
||||
|
||||
set(
|
||||
LIBRARY_SRC_FILES
|
||||
src/utils/MoneroUtils.cpp
|
||||
src/daemon/MoneroDaemonModel.cpp
|
||||
src/daemon/MoneroDaemon.cpp
|
||||
src/wallet/MoneroWalletModel.cpp
|
||||
src/wallet/MoneroWallet.cpp
|
||||
src/utils/MoneroUtils.cpp
|
||||
)
|
||||
|
||||
add_library(monero-cpp SHARED ${LIBRARY_SRC_FILES})
|
||||
@@ -285,7 +285,7 @@ target_link_libraries(monero-cpp
|
||||
# Build C++ scratchpad
|
||||
########################
|
||||
|
||||
###[[ --- START BLOCK COMMENT ---
|
||||
#[[ --- START BLOCK COMMENT ---
|
||||
|
||||
set(
|
||||
SCRATCHPAD_SRC_FILES
|
||||
@@ -338,4 +338,4 @@ target_link_libraries(scratchpad
|
||||
${EXTRA_LIBRARIES}
|
||||
)
|
||||
|
||||
###]] # --- END BLOCK COMMENT ---
|
||||
#]] # --- END BLOCK COMMENT ---
|
||||
@@ -109,6 +109,8 @@ namespace monero {
|
||||
|
||||
/**
|
||||
* Models a Monero block header which contains information about the block.
|
||||
*
|
||||
* TODO: a header that is transmitted may have fewer fields like cryptonote::block_header; separate?
|
||||
*/
|
||||
struct MoneroBlockHeader : public SerializableStruct {
|
||||
boost::optional<string> id;
|
||||
|
||||
@@ -469,3 +469,36 @@ boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint32_t> n
|
||||
}
|
||||
return numsNode;
|
||||
}
|
||||
|
||||
shared_ptr<MoneroBlock> MoneroUtils::cnBlockToBlock(const cryptonote::block& cnBlock) {
|
||||
cryptonote::block temp = cnBlock;
|
||||
cout << cryptonote::obj_to_json_str(temp) << endl;
|
||||
shared_ptr<MoneroBlock> block = make_shared<MoneroBlock>();
|
||||
block->majorVersion = cnBlock.major_version;
|
||||
block->minorVersion = cnBlock.minor_version;
|
||||
block->timestamp = cnBlock.timestamp;
|
||||
block->prevId = epee::string_tools::pod_to_hex(cnBlock.prev_id);
|
||||
block->nonce = cnBlock.nonce;
|
||||
block->coinbaseTx = MoneroUtils::cnTransactionToTx(cnBlock.miner_tx);
|
||||
for (const crypto::hash& txHash : cnBlock.tx_hashes) {
|
||||
block->txIds.push_back(epee::string_tools::pod_to_hex(txHash));
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
shared_ptr<MoneroTx> MoneroUtils::cnTransactionToTx(const cryptonote::transaction& cnTx) {
|
||||
shared_ptr<MoneroTx> tx = make_shared<MoneroTx>();
|
||||
//tx->version = cnTx.version;
|
||||
tx->unlockTime = cnTx.unlock_time;
|
||||
tx->id = epee::string_tools::pod_to_hex(cnTx.hash);
|
||||
return tx;
|
||||
|
||||
// TODO: finish this
|
||||
// std::vector<txin_v> vin;
|
||||
// std::vector<tx_out> vout;
|
||||
// std::vector<uint8_t> extra;
|
||||
// std::vector<std::vector<crypto::signature> > signatures;
|
||||
// rct::rctSig rct_signatures;
|
||||
// mutable size_t blob_size;
|
||||
// throw runtime_error("cnTransactionToTx not implemented");
|
||||
}
|
||||
|
||||
+32
-14
@@ -84,6 +84,38 @@ namespace MoneroUtils
|
||||
|
||||
string serialize(const boost::property_tree::ptree& node);
|
||||
|
||||
/**
|
||||
* Convert a Monero Core cryptonote::block to a block in this library's native model.
|
||||
*
|
||||
* @param cnBlock is the Core block to convert
|
||||
* @return a block in this library's native model
|
||||
*/
|
||||
shared_ptr<MoneroBlock> cnBlockToBlock(const cryptonote::block& cnBlock);
|
||||
|
||||
/**
|
||||
* Convert a Monero Core cryptonote::transaction to a transaction in this library's native model.
|
||||
*
|
||||
* @param cnTransaction is the Core transaction to convert
|
||||
* @return a transaction in this library's native model
|
||||
*/
|
||||
shared_ptr<MoneroTx> cnTransactionToTx(const cryptonote::transaction& cnTransaction);
|
||||
|
||||
/**
|
||||
* Modified from core_rpc_server.cpp to return a string.
|
||||
*
|
||||
* TODO: remove this duplicate, use core_rpc_server instead
|
||||
*/
|
||||
static std::string get_pruned_tx_json(cryptonote::transaction &tx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
json_archive<true> ar(ss);
|
||||
bool r = tx.serialize_base(ar);
|
||||
CHECK_AND_ASSERT_MES(r, std::string(), "Failed to serialize rct signatures base");
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// ------------------------- VALUE RECONCILATION- ---------------------------
|
||||
|
||||
// TODO: template implementation here, could move to MoneroUtils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
|
||||
template <class T> boost::property_tree::ptree toPropertyTree(const vector<shared_ptr<T>> types) {
|
||||
boost::property_tree::ptree typeNodes;
|
||||
@@ -193,19 +225,5 @@ namespace MoneroUtils
|
||||
// boost::optional<T> reconcile(const boost::optional<T>& val1, const boost::optional<T>& val2) {
|
||||
// return reconcile(val1, val2, boost::none, boost::none, boost::none);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Modified from core_rpc_server.cpp to return a string.
|
||||
*
|
||||
* TODO: remove this duplicate, use core_rpc_server instead
|
||||
*/
|
||||
static std::string get_pruned_tx_json(cryptonote::transaction &tx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
json_archive<true> ar(ss);
|
||||
bool r = tx.serialize_base(ar);
|
||||
CHECK_AND_ASSERT_MES(r, std::string(), "Failed to serialize rct signatures base");
|
||||
return ss.str();
|
||||
}
|
||||
}
|
||||
#endif /* MoneroUtils_h */
|
||||
|
||||
@@ -698,12 +698,13 @@ namespace monero {
|
||||
|
||||
virtual void on_new_block(uint64_t height, const cryptonote::block& cnBlock) {
|
||||
|
||||
// // convert cryptonote block to library model
|
||||
// shared_ptr<MoneroBlock> block = MoneroUtils::cnBlockToBlock(cnBlock);
|
||||
// block->height = height;
|
||||
// listener->onNewBlock(*block);
|
||||
|
||||
// notify listener of block
|
||||
if (listener != boost::none) {
|
||||
MoneroBlock block;
|
||||
block.height = height;
|
||||
listener.get().onNewBlock(block);
|
||||
}
|
||||
if (listener != boost::none) listener->onNewBlock(height);
|
||||
|
||||
// notify listeners of sync progress
|
||||
if (syncStartHeight != boost::none && height >= *syncStartHeight) {
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace monero {
|
||||
*
|
||||
* @param block is the newly processed block
|
||||
*/
|
||||
virtual void onNewBlock(MoneroBlock& block) {};
|
||||
virtual void onNewBlock(uint64_t height) {};
|
||||
};
|
||||
|
||||
// forward declaration of internal wallet2 listener
|
||||
|
||||
Reference in New Issue
Block a user