Skip to content

Commit

Permalink
walletd integrated address support
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptokatz committed Aug 23, 2018
1 parent 2cd1420 commit 0abe402
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Expand Up @@ -73,6 +73,9 @@
"xutility": "cpp",
"emmintrin.h": "c",
"resumable": "cpp",
"xthread": "cpp"
"xthread": "cpp",
"sparse_hash_map": "cpp",
"sparse_hash_set": "cpp",
"sparsetable": "cpp"
}
}
14 changes: 14 additions & 0 deletions src/PaymentGate/PaymentServiceJsonRpcMessages.cpp
Expand Up @@ -118,6 +118,20 @@ void GetTransactionHashes::Response::serialize(CryptoNote::ISerializer& serializ
serializer(items, "items");
}

void CreateIntegrated::Request::serialize(CryptoNote::ISerializer& serializer) {
serializer(address, "address");

serializer(payment_id, "payment_id");
}

void CreateIntegrated::Response::serialize(CryptoNote::ISerializer& serializer) {
serializer(integrated_address, "integrated_address");
}





void TransferRpcInfo::serialize(CryptoNote::ISerializer& serializer) {
serializer(type, "type");
serializer(address, "address");
Expand Down
15 changes: 15 additions & 0 deletions src/PaymentGate/PaymentServiceJsonRpcMessages.h
Expand Up @@ -168,6 +168,21 @@ struct GetTransactionHashes {
};
};

struct CreateIntegrated {
struct Request {
std::string address;
std::string payment_id;

void serialize(CryptoNote::ISerializer& serializer);
};

struct Response {
std::string integrated_address;

void serialize(CryptoNote::ISerializer& serializer);
};
};

struct TransferRpcInfo {
uint8_t type;
std::string address;
Expand Down
34 changes: 33 additions & 1 deletion src/PaymentGate/PaymentServiceJsonRpcServer.cpp
Expand Up @@ -9,7 +9,23 @@

#include "PaymentServiceJsonRpcMessages.h"
#include "WalletService.h"

#include "Common/CommandLine.h"
#include "Common/StringTools.h"
#include "CryptoNoteCore/CryptoNoteFormatUtils.h"
#include "CryptoNoteCore/Account.h"
#include "crypto/hash.h"
#include "CryptoNoteCore/CryptoNoteBasic.h"
#include "CryptoNoteCore/CryptoNoteBasicImpl.h"
#include "WalletLegacy/WalletHelper.h"
#include "Common/Base58.h"
#include "Common/CommandLine.h"
#include "Common/SignalHandler.h"
#include "Common/StringTools.h"
#include "Common/PathTools.h"
#include "Common/Util.h"
#include "CryptoNoteCore/CryptoNoteFormatUtils.h"
#include "CryptoNoteCore/CryptoNoteTools.h"
#include "CryptoNoteProtocol/CryptoNoteProtocolHandler.h"
#include "Serialization/JsonInputValueSerializer.h"
#include "Serialization/JsonOutputStreamSerializer.h"

Expand All @@ -20,6 +36,7 @@ PaymentServiceJsonRpcServer::PaymentServiceJsonRpcServer(System::Dispatcher& sys
, service(service)
, logger(loggerGroup, "PaymentServiceJsonRpcServer")
{
handlers.emplace("createIntegrated", jsonHandler<CreateIntegrated::Request, CreateIntegrated::Response>(std::bind(&PaymentServiceJsonRpcServer::handleCreateIntegrated, this, std::placeholders::_1, std::placeholders::_2)));
handlers.emplace("reset", jsonHandler<Reset::Request, Reset::Response>(std::bind(&PaymentServiceJsonRpcServer::handleReset, this, std::placeholders::_1, std::placeholders::_2)));
handlers.emplace("createAddress", jsonHandler<CreateAddress::Request, CreateAddress::Response>(std::bind(&PaymentServiceJsonRpcServer::handleCreateAddress, this, std::placeholders::_1, std::placeholders::_2)));
handlers.emplace("deleteAddress", jsonHandler<DeleteAddress::Request, DeleteAddress::Response>(std::bind(&PaymentServiceJsonRpcServer::handleDeleteAddress, this, std::placeholders::_1, std::placeholders::_2)));
Expand Down Expand Up @@ -98,6 +115,21 @@ std::error_code PaymentServiceJsonRpcServer::handleCreateAddress(const CreateAdd
}
}

/* ------------------------------------------------------------------------------ */

/* CREATE INTEGRATED */

std::error_code PaymentServiceJsonRpcServer::handleCreateIntegrated(const CreateIntegrated::Request& request, CreateIntegrated::Response& response)
{

if (!request.payment_id.empty() && !request.address.empty())
{
return service.createIntegratedAddress(request, response.integrated_address);
}
}

/* ----------------------------------------------------------------------------- */

std::error_code PaymentServiceJsonRpcServer::handleDeleteAddress(const DeleteAddress::Request& request, DeleteAddress::Response& response) {
return service.deleteAddress(request.address);
}
Expand Down
1 change: 1 addition & 0 deletions src/PaymentGate/PaymentServiceJsonRpcServer.h
Expand Up @@ -60,6 +60,7 @@ class PaymentServiceJsonRpcServer : public CryptoNote::JsonRpcServer {
std::unordered_map<std::string, HandlerFunction> handlers;

std::error_code handleReset(const Reset::Request& request, Reset::Response& response);
std::error_code handleCreateIntegrated(const CreateIntegrated::Request& request, CreateIntegrated::Response& response);
std::error_code handleCreateAddress(const CreateAddress::Request& request, CreateAddress::Response& response);
std::error_code handleDeleteAddress(const DeleteAddress::Request& request, DeleteAddress::Response& response);
std::error_code handleGetSpendKeys(const GetSpendKeys::Request& request, GetSpendKeys::Response& response);
Expand Down
50 changes: 50 additions & 0 deletions src/PaymentGate/WalletService.cpp
Expand Up @@ -33,6 +33,22 @@
#include "Wallet/WalletErrors.h"
#include "Wallet/WalletUtils.h"
#include "WalletServiceErrorCategory.h"
#include "CryptoNoteCore/CryptoNoteTools.h"

#include "Common/CommandLine.h"
#include "Common/StringTools.h"
#include "CryptoNoteCore/CryptoNoteFormatUtils.h"
#include "CryptoNoteCore/Account.h"
#include "crypto/hash.h"
#include "CryptoNoteCore/CryptoNoteBasic.h"
#include "CryptoNoteCore/CryptoNoteBasicImpl.h"
#include "WalletLegacy/WalletHelper.h"
#include "Common/Base58.h"
#include "Common/CommandLine.h"
#include "Common/SignalHandler.h"
#include "Common/StringTools.h"
#include "Common/PathTools.h"
#include "CryptoNoteProtocol/CryptoNoteProtocolHandler.h"

namespace PaymentService {

Expand Down Expand Up @@ -924,6 +940,40 @@ std::error_code WalletService::createDelayedTransaction(const CreateDelayedTrans
return std::error_code();
}

/* ---------------------------------------------------------------------------- */

/* CREATE INTEGRATED */

std::error_code WalletService::createIntegratedAddress(const CreateIntegrated::Request& request, std::string& integrated_address)
{
std::string payment_id_str = request.payment_id;
std::string address_str = request.address;

uint64_t prefix;
CryptoNote::AccountPublicAddress addr;

/* get the spend and view public keys from the address */
const bool valid = CryptoNote::parseAccountAddressString(prefix,
addr,
address_str);

CryptoNote::BinaryArray ba;
CryptoNote::toBinaryArray(addr, ba);
std::string keys = Common::asString(ba);

/* create the integrated address the same way you make a public address */
integrated_address = Tools::Base58::encode_addr (
CryptoNote::parameters::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX,
payment_id_str + keys
);

return std::error_code();
}

/* ------------------------------------------------------------------------------------ */



std::error_code WalletService::getDelayedTransactionHashes(std::vector<std::string>& transactionHashes) {
try {
System::EventLock lk(readyEvent);
Expand Down
1 change: 1 addition & 0 deletions src/PaymentGate/WalletService.h
Expand Up @@ -63,6 +63,7 @@ class WalletService {
std::error_code getAddresses(std::vector<std::string>& addresses);
std::error_code sendTransaction(const SendTransaction::Request& request, std::string& transactionHash, std::string& transactionSecretKey);
std::error_code createDelayedTransaction(const CreateDelayedTransaction::Request& request, std::string& transactionHash);
std::error_code createIntegratedAddress(const CreateIntegrated::Request& request, std::string& integrated_address);
std::error_code getDelayedTransactionHashes(std::vector<std::string>& transactionHashes);
std::error_code deleteDelayedTransaction(const std::string& transactionHash);
std::error_code sendDelayedTransaction(const std::string& transactionHash);
Expand Down

0 comments on commit 0abe402

Please sign in to comment.