diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 9dcceb9..2d0f0dd 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -1233,7 +1233,7 @@ namespace monero { return txIds; } - string MoneroWallet::createPaymentUri(const MoneroSendRequest& request) { + string MoneroWallet::createPaymentUri(const MoneroSendRequest& request) const { cout << "createPaymentUri()" << endl; // validate request @@ -1241,7 +1241,7 @@ namespace monero { if (request.destinations.at(0)->address == boost::none) throw runtime_error("Must provide destination address"); if (request.destinations.at(0)->amount == boost::none) throw runtime_error("Must provide destination amount"); - // prep params for wallet2 + // prepare wallet2 params string address = request.destinations.at(0)->address.get(); string paymentId = request.paymentId == boost::none ? "" : request.paymentId.get(); uint64_t amount = request.destinations.at(0)->amount.get(); @@ -1255,6 +1255,34 @@ namespace monero { return uri; } + shared_ptr MoneroWallet::parsePaymentUri(const string& uri) const { + cout << "parsePaymentUri(" << uri << ")" << endl; + + // decode uri to parameters + string address; + string paymentId; + uint64_t amount = 0; + string note; + string recipientName; + vector unknownParameters; + string error; + if (!wallet2->parse_uri(uri, address, paymentId, amount, note, recipientName, unknownParameters, error)) { + throw runtime_error("Error parsing URI: " + error); + } + + // initialize send request + shared_ptr sendRequest = shared_ptr(new MoneroSendRequest()); + shared_ptr destination = shared_ptr(new MoneroDestination()); + sendRequest->destinations.push_back(destination); + if (!address.empty()) destination->address = address; + destination->amount = amount; + if (!paymentId.empty()) sendRequest->paymentId = paymentId; + if (!note.empty()) sendRequest->note = note; + if (!recipientName.empty()) sendRequest->recipientName = recipientName; + if (!unknownParameters.empty()) cout << "WARNING in MoneroWallet::parsePaymentUri: URI contains unknown parameters which are discarded" << endl; // TODO: return unknown parameters? + return sendRequest; + } + void MoneroWallet::save() { cout << "save()" << endl; save("", ""); diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 34408be..9951c84 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -987,16 +987,16 @@ namespace monero { * @param request specifies configuration for a potential tx * @return is the payment uri */ - string createPaymentUri(const MoneroSendRequest& request); + string createPaymentUri(const MoneroSendRequest& request) const; + + /** + * Parses a payment URI to a send request. + * + * @param uri is the payment uri to parse + * @return the send request parsed from the uri + */ + shared_ptr parsePaymentUri(const string& uri) const; -// /** -// * Parses a payment URI to a send configuration. -// * -// * @param uri is the payment uri to parse -// * @return the send configuration parsed from the uri -// */ -// public MoneroSendRequest parsePaymentUri(string uri); -// // /** // * Export all outputs in hex format. // *