Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add walletd RPC method hasAddress #224

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/IWallet.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018-2019, Karbo developers
// Copyright (c) 2016-2024, The Karbo developers
//
// This file is part of Karbo.
//
Expand Down Expand Up @@ -151,6 +151,8 @@ class IWallet {

virtual size_t getAddressCount() const = 0;
virtual std::string getAddress(size_t index) const = 0;
virtual bool isMyAddress(const std::string& address) const = 0;

virtual AccountPublicAddress getAccountPublicAddress(size_t index) const = 0;
virtual KeyPair getAddressSpendKey(size_t index) const = 0;
virtual KeyPair getAddressSpendKey(const std::string& address) const = 0;
Expand Down
15 changes: 13 additions & 2 deletions src/PaymentGate/PaymentServiceJsonRpcMessages.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018-2019 The Cash2 developers
// Copyright (c) 2018-2019 The Karbo developers
// Copyright (c) 2018-2019, The Cash2 developers
// Copyright (c) 2021-2023, The Talleo developers
// Copyright (c) 2016-2024, The Karbo developers
//
// This file is part of Karbo.
//
Expand Down Expand Up @@ -156,6 +157,16 @@ void DeleteAddress::Request::serialize(CryptoNote::ISerializer& serializer) {
void DeleteAddress::Response::serialize(CryptoNote::ISerializer& serializer) {
}

void HasAddress::Request::serialize(CryptoNote::ISerializer& serializer) {
if (!serializer(address, "address")) {
throw RequestSerializationError();
}
}

void HasAddress::Response::serialize(CryptoNote::ISerializer& serializer) {
serializer(isOurs, "isOurs");
}

void GetSpendKeys::Request::serialize(CryptoNote::ISerializer& serializer) {
if (!serializer(address, "address")) {
throw RequestSerializationError();
Expand Down
14 changes: 14 additions & 0 deletions src/PaymentGate/PaymentServiceJsonRpcMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ struct DeleteAddress {
};
};

struct HasAddress {
struct Request {
std::string address;

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

struct Response {
bool isOurs;

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

struct GetSpendKeys {
struct Request {
std::string address;
Expand Down
10 changes: 8 additions & 2 deletions src/PaymentGate/PaymentServiceJsonRpcServer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018-2019 The Cash2 developers
// Copyright (c) 2018-2019 The Karbo developers
// Copyright (c) 2018-2019, The Cash2 developers
// Copyright (c) 2021-2023, The Talleo developers
// Copyright (c) 2016-2024, The Karbo developers
//
// This file is part of Karbo.
//
Expand Down Expand Up @@ -43,6 +44,7 @@ PaymentServiceJsonRpcServer::PaymentServiceJsonRpcServer(System::Dispatcher* sys
handlers.emplace("createAddress", jsonHandler<CreateAddress::Request, CreateAddress::Response>(std::bind(&PaymentServiceJsonRpcServer::handleCreateAddress, this, std::placeholders::_1, std::placeholders::_2)));
handlers.emplace("createAddressList", jsonHandler<CreateAddressList::Request, CreateAddressList::Response>(std::bind(&PaymentServiceJsonRpcServer::handleCreateAddressList, 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)));
handlers.emplace("hasAddress", jsonHandler<HasAddress::Request, HasAddress::Response>(std::bind(&PaymentServiceJsonRpcServer::handleHasAddress, this, std::placeholders::_1, std::placeholders::_2)));
handlers.emplace("getSpendKeys", jsonHandler<GetSpendKeys::Request, GetSpendKeys::Response>(std::bind(&PaymentServiceJsonRpcServer::handleGetSpendKeys, this, std::placeholders::_1, std::placeholders::_2)));
handlers.emplace("getBalance", jsonHandler<GetBalance::Request, GetBalance::Response>(std::bind(&PaymentServiceJsonRpcServer::handleGetBalance, this, std::placeholders::_1, std::placeholders::_2)));
handlers.emplace("getBlockHashes", jsonHandler<GetBlockHashes::Request, GetBlockHashes::Response>(std::bind(&PaymentServiceJsonRpcServer::handleGetBlockHashes, this, std::placeholders::_1, std::placeholders::_2)));
Expand Down Expand Up @@ -164,6 +166,10 @@ std::error_code PaymentServiceJsonRpcServer::handleDeleteAddress(const DeleteAdd
return service.deleteAddress(request.address);
}

std::error_code PaymentServiceJsonRpcServer::handleHasAddress(const HasAddress::Request& request, HasAddress::Response& response) {
return service.hasAddress(request.address, response.isOurs);
}

std::error_code PaymentServiceJsonRpcServer::handleGetSpendKeys(const GetSpendKeys::Request& request, GetSpendKeys::Response& response) {
return service.getSpendkeys(request.address, response.spendPublicKey, response.spendSecretKey);
}
Expand Down
6 changes: 4 additions & 2 deletions src/PaymentGate/PaymentServiceJsonRpcServer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018-2019 The Cash2 developers
// Copyright (c) 2018-2022 The Karbo developers
// Copyright (c) 2018-2019, The Cash2 developers
// Copyright (c) 2021-2023, The Talleo developers
// Copyright (c) 2016-2024, The Karbo developers
//
// This file is part of Karbo.
//
Expand Down Expand Up @@ -80,6 +81,7 @@ class PaymentServiceJsonRpcServer : public CryptoNote::JsonRpcServer {
std::error_code handleCreateAddress(const CreateAddress::Request& request, CreateAddress::Response& response);
std::error_code handleCreateAddressList(const CreateAddressList::Request& request, CreateAddressList::Response& response);
std::error_code handleDeleteAddress(const DeleteAddress::Request& request, DeleteAddress::Response& response);
std::error_code handleHasAddress(const HasAddress::Request& request, HasAddress::Response& response);
std::error_code handleGetSpendKeys(const GetSpendKeys::Request& request, GetSpendKeys::Response& response);
std::error_code handleGetBalance(const GetBalance::Request& request, GetBalance::Response& response);
std::error_code handleGetBlockHashes(const GetBlockHashes::Request& request, GetBlockHashes::Response& response);
Expand Down
25 changes: 24 additions & 1 deletion src/PaymentGate/WalletService.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018-2019 The Cash2 developers
// Copyright (c) 2016-2022, Karbo developers
// Copyright (c) 2021-2023, The Talleo developers
// Copyright (c) 2016-2024, The Karbo developers
//
// This file is part of Karbo.
//
Expand Down Expand Up @@ -840,6 +841,28 @@ std::error_code WalletService::deleteAddress(const std::string& address) {
return std::error_code();
}

std::error_code WalletService::hasAddress(const std::string& address, bool& isOurs) {
try {
System::EventLock lk(readyEvent);

logger(Logging::DEBUGGING) << "Has address request came";

isOurs = wallet.isMyAddress(address);
if (!isOurs) {
logger(Logging::DEBUGGING, Logging::BRIGHT_YELLOW) << "Address " << address << " doesn't exist in container";
//return make_error_code(CryptoNote::error::WalletServiceErrorCode::OBJECT_NOT_FOUND);
} else {
logger(Logging::DEBUGGING) << "Address " << address << " exists in container";
}
}
catch (std::system_error& x) {
logger(Logging::DEBUGGING, Logging::BRIGHT_YELLOW) << "Error while checking if address exists in container: " << x.what();
return x.code();
}

return std::error_code();
}

std::error_code WalletService::getSpendkeys(const std::string& address, std::string& publicSpendKeyText, std::string& secretSpendKeyText) {
try {
System::EventLock lk(readyEvent);
Expand Down
6 changes: 4 additions & 2 deletions src/PaymentGate/WalletService.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) 2012-2016, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018-2019 The Cash2 developers
// Copyright (c) 2016-2019 The Karbo developers
// Copyright (c) 2018-2019, The Cash2 developers
// Copyright (c) 2021-2023, The Talleo developers
// Copyright (c) 2016-2024, The Karbo developers
//
// This file is part of Karbo.
//
Expand Down Expand Up @@ -82,6 +83,7 @@ class WalletService {
std::error_code createTrackingAddress(const std::string& spendPublicKeyText, std::string& address);
std::error_code createTrackingAddress(const std::string& spendPublicKeyText, const uint32_t scanHeight, std::string& address);
std::error_code deleteAddress(const std::string& address);
std::error_code hasAddress(const std::string& address, bool& isOurs);
std::error_code getSpendkeys(const std::string& address, std::string& publicSpendKeyText, std::string& secretSpendKeyText);
std::error_code getBalance(const std::string& address, uint64_t& availableBalance, uint64_t& lockedAmount);
std::error_code getBalance(uint64_t& availableBalance, uint64_t& lockedAmount);
Expand Down
4 changes: 2 additions & 2 deletions src/Wallet/WalletGreen.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018-2019, Karbo developers
// Copyright (c) 2016-2024, The Karbo developers
//
// This file is part of Karbo.
//
Expand Down Expand Up @@ -60,6 +60,7 @@ class WalletGreen : public IWallet,
virtual size_t getAddressCount() const override;
virtual std::string getAddress(size_t index) const override;
virtual AccountPublicAddress getAccountPublicAddress(size_t index) const override;
virtual bool isMyAddress(const std::string& address) const override;
virtual KeyPair getAddressSpendKey(size_t index) const override;
virtual KeyPair getAddressSpendKey(const std::string& address) const override;
virtual KeyPair getViewKey() const override;
Expand Down Expand Up @@ -369,7 +370,6 @@ class WalletGreen : public IWallet,
void filterOutTransactions(WalletTransactions& transactions, WalletTransfers& transfers, std::function<bool (const WalletTransaction&)>&& pred) const;
void initBlockchain(const Crypto::PublicKey& viewPublicKey);
CryptoNote::AccountPublicAddress getChangeDestination(const std::string& changeDestinationAddress, const std::vector<std::string>& sourceAddresses) const;
bool isMyAddress(const std::string& address) const;

void deleteContainerFromUnlockTransactionJobs(const ITransfersContainer* container);
std::vector<size_t> deleteTransfersForAddress(const std::string& address, std::vector<size_t>& deletedTransactions);
Expand Down
Loading