mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-18 23:58:59 +02:00
implement MoneroUtils::cnTxToTx();
support vins and extra in daemon model
This commit is contained in:
@@ -255,12 +255,12 @@ namespace monero {
|
||||
if (prunableHash != boost::none) node.put("prunableHash", *prunableHash);
|
||||
if (size != boost::none) node.put("size", *size);
|
||||
if (weight != boost::none) node.put("weight", *weight);
|
||||
if (!vins.empty()) node.add_child("vouts", MoneroUtils::toPropertyTree(vouts));
|
||||
if (!vins.empty()) node.add_child("vins", MoneroUtils::toPropertyTree(vins));
|
||||
if (!vouts.empty()) node.add_child("vouts", MoneroUtils::toPropertyTree(vouts));
|
||||
if (!outputIndices.empty()) throw runtime_error("outputIndices not implemented");
|
||||
if (metadata != boost::none) node.put("metadata", *metadata);
|
||||
if (commonTxSets != boost::none) throw runtime_error("commonTxSets not implemented");
|
||||
if (!extra.empty()) throw runtime_error("extra not implemented");
|
||||
if (!extra.empty()) node.add_child("extra", MoneroUtils::toPropertyTree(extra));
|
||||
if (rctSignatures != boost::none) throw runtime_error("rctSignatures not implemented");
|
||||
if (rctSigPrunable != boost::none) throw runtime_error("rctSigPrunable not implemented");
|
||||
if (isKeptByBlock != boost::none) node.put("isKeptByBlock", *isKeptByBlock);
|
||||
@@ -435,7 +435,7 @@ namespace monero {
|
||||
if (src->keyImage != boost::none) tgt->keyImage = src->keyImage.get()->copy(src->keyImage.get(), make_shared<MoneroKeyImage>());
|
||||
tgt->amount = src->amount;
|
||||
tgt->index = src->index;
|
||||
if (!src->ringOutputIndices.empty()) tgt->ringOutputIndices = vector<uint32_t>(src->ringOutputIndices);
|
||||
if (!src->ringOutputIndices.empty()) tgt->ringOutputIndices = vector<uint64_t>(src->ringOutputIndices);
|
||||
tgt->stealthPublicKey = src->stealthPublicKey;
|
||||
return tgt;
|
||||
}
|
||||
@@ -445,7 +445,7 @@ namespace monero {
|
||||
if (keyImage != boost::none) node.add_child("keyImage", (*keyImage)->toPropertyTree());
|
||||
if (amount != boost::none) node.put("amount", *amount);
|
||||
if (index != boost::none) node.put("index", *index);
|
||||
if (!ringOutputIndices.empty()) throw runtime_error("MoneroOutput::toPropertyTree() ringOutputIndices not implemented");
|
||||
if (!ringOutputIndices.empty()) node.add_child("ringOutputIndices", MoneroUtils::toPropertyTree(ringOutputIndices));
|
||||
if (stealthPublicKey != boost::none) node.put("stealthPublicKey", *stealthPublicKey);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace monero {
|
||||
static const string DEFAULT_PAYMENT_ID; // default payment id "0000000000000000"
|
||||
boost::optional<shared_ptr<MoneroBlock>> block;
|
||||
boost::optional<string> id;
|
||||
boost::optional<string> version;
|
||||
boost::optional<uint32_t> version;
|
||||
boost::optional<bool> isCoinbase;
|
||||
boost::optional<string> paymentId;
|
||||
boost::optional<uint64_t> fee;
|
||||
@@ -183,7 +183,7 @@ namespace monero {
|
||||
vector<uint32_t> outputIndices;
|
||||
boost::optional<string> metadata;
|
||||
boost::optional<string> commonTxSets;
|
||||
vector<uint32_t> extra;
|
||||
vector<uint8_t> extra;
|
||||
boost::optional<string> rctSignatures; // TODO: implement
|
||||
boost::optional<string> rctSigPrunable; // TODO: implement
|
||||
boost::optional<bool> isKeptByBlock;
|
||||
@@ -220,7 +220,7 @@ namespace monero {
|
||||
boost::optional<shared_ptr<MoneroKeyImage>> keyImage;
|
||||
boost::optional<uint64_t> amount;
|
||||
boost::optional<uint64_t> index;
|
||||
vector<uint32_t> ringOutputIndices;
|
||||
vector<uint64_t> ringOutputIndices;
|
||||
boost::optional<string> stealthPublicKey;
|
||||
|
||||
shared_ptr<MoneroOutput> copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const;
|
||||
|
||||
@@ -450,7 +450,7 @@ string MoneroUtils::serialize(const boost::property_tree::ptree& node) {
|
||||
return str.substr(0, str.size() - 1); // strip newline
|
||||
}
|
||||
|
||||
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<string> strs) {
|
||||
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<string>& strs) {
|
||||
boost::property_tree::ptree strsNode;
|
||||
for (const auto& str : strs) {
|
||||
boost::property_tree::ptree strNode;
|
||||
@@ -460,7 +460,28 @@ boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<string> str
|
||||
return strsNode;
|
||||
}
|
||||
|
||||
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint32_t> nums) {
|
||||
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint8_t>& nums) {
|
||||
boost::property_tree::ptree numsNode;
|
||||
for (const auto& num : nums) {
|
||||
boost::property_tree::ptree numNode;
|
||||
numNode.put("", num);
|
||||
numsNode.push_back(std::make_pair("", numNode));
|
||||
}
|
||||
return numsNode;
|
||||
}
|
||||
|
||||
// TODO: remove these redundant implementations for different sizes?
|
||||
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint32_t>& nums) {
|
||||
boost::property_tree::ptree numsNode;
|
||||
for (const auto& num : nums) {
|
||||
boost::property_tree::ptree numNode;
|
||||
numNode.put("", num);
|
||||
numsNode.push_back(std::make_pair("", numNode));
|
||||
}
|
||||
return numsNode;
|
||||
}
|
||||
|
||||
boost::property_tree::ptree MoneroUtils::toPropertyTree(const vector<uint64_t>& nums) {
|
||||
boost::property_tree::ptree numsNode;
|
||||
for (const auto& num : nums) {
|
||||
boost::property_tree::ptree numNode;
|
||||
@@ -488,17 +509,41 @@ shared_ptr<MoneroBlock> MoneroUtils::cnBlockToBlock(const cryptonote::block& cnB
|
||||
|
||||
shared_ptr<MoneroTx> MoneroUtils::cnTxToTx(const cryptonote::transaction& cnTx, bool initAsTxWallet) {
|
||||
shared_ptr<MoneroTx> tx = initAsTxWallet ? make_shared<MoneroTxWallet>() : make_shared<MoneroTx>();
|
||||
//tx->version = cnTx.version;
|
||||
tx->version = cnTx.version;
|
||||
tx->unlockTime = cnTx.unlock_time;
|
||||
tx->id = epee::string_tools::pod_to_hex(cnTx.hash);
|
||||
tx->extra = cnTx.extra;
|
||||
|
||||
// init vins
|
||||
for (const txin_v& cnVin : cnTx.vin) {
|
||||
if (cnVin.which() != 0 && cnVin.which() != 3) throw runtime_error("Unsupported variant type");
|
||||
if (tx->isCoinbase == boost::none) tx->isCoinbase = cnVin.which() == 0;
|
||||
if (cnVin.which() != 3) continue; // only process txin_to_key of variant TODO: support other types, like 0 "gen" which is miner tx?
|
||||
shared_ptr<MoneroOutput> vin = initAsTxWallet ? make_shared<MoneroOutputWallet>() : make_shared<MoneroOutput>();
|
||||
vin->tx = tx;
|
||||
tx->vins.push_back(vin);
|
||||
const txin_to_key& txin = boost::get<txin_to_key>(cnVin);
|
||||
vin->amount = txin.amount;
|
||||
vin->ringOutputIndices = txin.key_offsets;
|
||||
crypto::key_image cnKeyImage = txin.k_image;
|
||||
vin->keyImage = make_shared<MoneroKeyImage>();
|
||||
vin->keyImage.get()->hex = epee::string_tools::pod_to_hex(cnKeyImage);
|
||||
}
|
||||
|
||||
// init vouts
|
||||
for (const tx_out& cnVout : cnTx.vout) {
|
||||
shared_ptr<MoneroOutput> vout = initAsTxWallet ? make_shared<MoneroOutputWallet>() : make_shared<MoneroOutput>();
|
||||
vout->tx = tx;
|
||||
tx->vouts.push_back(vout);
|
||||
vout->amount = cnVout.amount;
|
||||
const crypto::public_key& cnStealthPublicKey = boost::get<txout_to_key>(cnVout.target).key;
|
||||
vout->stealthPublicKey = epee::string_tools::pod_to_hex(cnStealthPublicKey);
|
||||
}
|
||||
|
||||
return tx;
|
||||
|
||||
// TODO: finish this
|
||||
// std::vector<txin_v> vin;
|
||||
// std::vector<tx_out> vout;
|
||||
// std::vector<uint8_t> extra;
|
||||
// TODO: finish this, cryptonote::transaction has:
|
||||
// std::vector<std::vector<crypto::signature> > signatures;
|
||||
// rct::rctSig rct_signatures;
|
||||
// mutable size_t blob_size;
|
||||
// throw runtime_error("cnTransactionToTx not implemented");
|
||||
}
|
||||
|
||||
@@ -116,10 +116,10 @@ namespace MoneroUtils
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// ------------------------- VALUE RECONCILATION- ---------------------------
|
||||
// ----------------------------- PROPERTY TREE ------------------------------
|
||||
|
||||
// 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) {
|
||||
template <class T> boost::property_tree::ptree toPropertyTree(const vector<shared_ptr<T>>& types) {
|
||||
boost::property_tree::ptree typeNodes;
|
||||
for (const auto& type : types) {
|
||||
typeNodes.push_back(std::make_pair("", type->toPropertyTree()));
|
||||
@@ -128,7 +128,7 @@ namespace MoneroUtils
|
||||
}
|
||||
|
||||
// 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<T> types) {
|
||||
template <class T> boost::property_tree::ptree toPropertyTree(const vector<T>& types) {
|
||||
boost::property_tree::ptree typeNodes;
|
||||
for (const auto& type : types) {
|
||||
typeNodes.push_back(std::make_pair("", type.toPropertyTree()));
|
||||
@@ -136,9 +136,12 @@ namespace MoneroUtils
|
||||
return typeNodes;
|
||||
}
|
||||
|
||||
boost::property_tree::ptree toPropertyTree(const vector<string> strs);
|
||||
boost::property_tree::ptree toPropertyTree(const vector<uint32_t> nums);
|
||||
boost::property_tree::ptree toPropertyTree(const vector<string>& strs);
|
||||
boost::property_tree::ptree toPropertyTree(const vector<uint8_t>& nums);
|
||||
boost::property_tree::ptree toPropertyTree(const vector<uint32_t>& nums);
|
||||
boost::property_tree::ptree toPropertyTree(const vector<uint64_t>& nums);
|
||||
|
||||
// ------------------------- VALUE RECONCILATION- ---------------------------
|
||||
|
||||
// TODO: refactor common template code
|
||||
template <class T, typename std::enable_if<std::is_same<T, string>::value, T>::type* = nullptr>
|
||||
|
||||
@@ -716,7 +716,6 @@ namespace monero {
|
||||
if (listener == boost::none) return;
|
||||
|
||||
// create native library tx
|
||||
// TODO **: fill this out
|
||||
shared_ptr<MoneroBlock> block = make_shared<MoneroBlock>();
|
||||
block->height = height;
|
||||
shared_ptr<MoneroTxWallet> tx = static_pointer_cast<MoneroTxWallet>(MoneroUtils::cnTxToTx(cnTx, true));
|
||||
|
||||
Reference in New Issue
Block a user