mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-20 00:28:41 +02:00
implement parsePaymentUri()
This commit is contained in:
@@ -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<MoneroSendRequest> 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<string> 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<MoneroSendRequest> sendRequest = shared_ptr<MoneroSendRequest>(new MoneroSendRequest());
|
||||
shared_ptr<MoneroDestination> destination = shared_ptr<MoneroDestination>(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("", "");
|
||||
|
||||
@@ -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<MoneroSendRequest> 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.
|
||||
// *
|
||||
|
||||
Reference in New Issue
Block a user