wip getTransfers();

compiling except missing txReq.height and transferReq.isOutgoing fields;
use boost::optional for struct members and accessors/mutators?
This commit is contained in:
woodser
2019-06-05 18:40:17 -04:00
parent ec7d3415ca
commit 1fe9d6d252
2 changed files with 112 additions and 40 deletions
+79 -7
View File
@@ -12,6 +12,19 @@ using namespace cryptonote;
*/
namespace monero {
// ---------------------------- PRIVATE HELPERS -----------------------------
bool boolEquals(bool val, shared_ptr<bool> ptr) {
return ptr == nullptr ? false : val == *ptr;
}
MoneroTransfer wallet2ToTransfer(const crypto::hash &txid, const crypto::hash &payment_id, const tools::wallet2::payment_details &pd) {
cout << "wallet2ToTransfer(3)" << endl;
throw runtime_error("not implemented");
}
// ----------------------------- WALLET LISTENER ----------------------------
/**
* Listens to wallet2 notifications in order to facilitate external wallet notifications.
*/
@@ -446,20 +459,79 @@ namespace monero {
string requestStr = ss.str();
cout << "Tx request: " << requestStr << endl;
// build parameters to wallet2->get_payments()
uint64_t min_height = request.minHeight == nullptr ? 0 : *request.minHeight;
uint64_t max_height = request.maxHeight == nullptr ? CRYPTONOTE_MAX_BLOCK_NUMBER : min((uint64_t) 0, *request.maxHeight);
throw runtime_error("getTxs() not implemented");
}
vector<MoneroTransfer> MoneroWallet::getTransfers(const MoneroTransferRequest& request) const {
cout << "getTransfers(request)" << endl;
// normalize transfer request
if (request.txRequest == nullptr) request.txRequest = shared_ptr<MoneroTxRequest>(make_shared<MoneroTxRequest>(MoneroTxRequest()));
MoneroTxRequest& txReq = *request.txRequest;
// build parameters for wallet2->get_payments()
uint64_t minHeight = txReq.minHeight == nullptr ? 0 : *txReq.minHeight;
uint64_t maxHeight = txReq.maxHeight == nullptr ? CRYPTONOTE_MAX_BLOCK_NUMBER : min((uint64_t) CRYPTONOTE_MAX_BLOCK_NUMBER, *txReq.maxHeight);
boost::optional<uint32_t> accountIndex = boost::none;
if (request.transferRequest != nullptr && request.transferRequest->accountIndex != nullptr) accountIndex = *(request.transferRequest->accountIndex);
if (request.accountIndex != nullptr) accountIndex = *request.accountIndex;
std::set<uint32_t> subaddressIndices;
if (request.transferRequest != nullptr) {
for (int i = 0; i < request.transferRequest->subaddressIndices.size(); i++) {
subaddressIndices.insert(request.transferRequest->subaddressIndices[i]);
for (int i = 0; i < request.subaddressIndices.size(); i++) {
subaddressIndices.insert(request.subaddressIndices[i]);
}
// TODO: txReq does not have field height because block has height; used accessor in Java
// TODO: transferReq does not have field isOutgoing because isIncoming is sufficient , but then need bool logic on isOutgoing
// translate from MoneroTxRequest to in, out, pending, pool, failed terminology
bool canBeConfirmed = !boolEquals(false, txReq.isConfirmed) && !boolEquals(true, txReq.inTxPool) && !boolEquals(true, txReq.isFailed) && !boolEquals(false, txReq.isRelayed);
bool canBeInTxPool = !boolEquals(true, txReq.isConfirmed) && !boolEquals(false, txReq.inTxPool) && !boolEquals(true, txReq.isFailed) && !boolEquals(false, txReq.isRelayed) && txReq.height == nullptr && txReq.minHeight == nullptr;
bool canBeIncoming = !boolEquals(false, request.isIncoming) && !boolEquals(true, request.isOutgoing) && !boolEquals(true, request.hasDestinations);
bool canBeOutgoing = !boolEquals(false, request.isOutgoing) && !boolEquals(true, request.isIncoming);
bool isIn = canBeIncoming && canBeConfirmed;
bool isOut = canBeOutgoing && canBeConfirmed;
bool isPending = canBeOutgoing && canBeInTxPool;
bool isPool = canBeIncoming && canBeInTxPool;
bool isFailed = !boolEquals(false, txReq.isFailed) && !boolEquals(true, txReq.isConfirmed) && !boolEquals(true, txReq.inTxPool);
// TODO: this duplicates common transfer txs
// collect transfers
vector<MoneroTransfer> transfers;
// get confirmed incoming transfers
if (isIn) {
std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
wallet2->get_payments(payments, minHeight, maxHeight, accountIndex, subaddressIndices);
for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
transfers.push_back(wallet2ToTransfer(i->second.m_tx_hash, i->first, i->second));
}
}
// get confirmed outgoing transfers
if (isOut) {
throw runtime_error("Not implemented");
}
// get unconfirmed outgoing transfers
if (isPending || isFailed) {
throw runtime_error("Not implemented");
}
// get unconfirmed incoming transfers
if (isPool) {
throw runtime_error("Not implemented");
}
return transfers;
}
vector<MoneroOutputWallet> MoneroWallet::getOutputs(const MoneroOutputRequest& request) const {
cout << "getOutputs(request)" << endl;
throw runtime_error("Not implemented");
}
+33 -33
View File
@@ -688,25 +688,25 @@ namespace monero {
// * @return transfers to/from the subaddress
// */
// public List<MoneroTransfer> getTransfers(int accountIdx, int subaddressIdx);
//
// /**
// * Get incoming and outgoing transfers to and from this wallet. An outgoing
// * transfer represents a total amount sent from one or more subaddresses
// * within an account to individual destination addresses, each with their
// * own amount. An incoming transfer represents a total amount received into
// * a subaddress within an account. Transfers belong to transactions which
// * are stored on the blockchain.
// *
// * Query results can be filtered by passing in a MoneroTransferRequest.
// * Transfers must meet every criteria defined in the request in order to be
// * returned. All filtering is optional and no filtering is applied when not
// * defined.
// *
// * @param request filters query results (optional)
// * @return wallet transfers per the request
// */
// public List<MoneroTransfer> getTransfers(MoneroTransferRequest request);
//
/**
* Get incoming and outgoing transfers to and from this wallet. An outgoing
* transfer represents a total amount sent from one or more subaddresses
* within an account to individual destination addresses, each with their
* own amount. An incoming transfer represents a total amount received into
* a subaddress within an account. Transfers belong to transactions which
* are stored on the blockchain.
*
* Query results can be filtered by passing in a MoneroTransferRequest.
* Transfers must meet every criteria defined in the request in order to be
* returned. All filtering is optional and no filtering is applied when not
* defined.
*
* @param request filters query results (optional)
* @return wallet transfers per the request
*/
vector<MoneroTransfer> getTransfers(const MoneroTransferRequest& request) const;
// /**
// * Get outputs created from previous transactions that belong to the wallet
// * (i.e. that the wallet can spend one time). Outputs are part of
@@ -715,20 +715,20 @@ namespace monero {
// * @return List<MoneroOutputWallet> are all wallet outputs
// */
// public List<MoneroOutputWallet> getOutputs();
//
// /**
// * Get outputs created from previous transactions that belong to the wallet
// * (i.e. that the wallet can spend one time). Outputs are part of
// * transactions which are stored in blocks on the blockchain.
// *
// * Results can be configured by passing a MoneroOutputRequest. Outputs must
// * meet every criteria defined in the request in order to be returned. All
// * filtering is optional and no filtering is applied when not defined.
// *
// * @param request specifies request options (optional)
// * @return List<MoneroOutputWallet> are wallet outputs per the request
// */
// public List<MoneroOutputWallet> getOutputs(MoneroOutputRequest request);
/**
* Get outputs created from previous transactions that belong to the wallet
* (i.e. that the wallet can spend one time). Outputs are part of
* transactions which are stored in blocks on the blockchain.
*
* Results can be configured by passing a MoneroOutputRequest. Outputs must
* meet every criteria defined in the request in order to be returned. All
* filtering is optional and no filtering is applied when not defined.
*
* @param request specifies request options (optional)
* @return List<MoneroOutputWallet> are wallet outputs per the request
*/
vector<MoneroOutputWallet> getOutputs(const MoneroOutputRequest& request) const;
//
// /**
// * Get all signed key images.