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

Walletd improvements #317

Merged
merged 10 commits into from
Dec 13, 2022
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
1 change: 1 addition & 0 deletions include/ITransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class ITransactionWriter {

// transaction info
virtual void setTransactionSecretKey(const crypto::SecretKey& key) = 0;
virtual void setDeterministicTransactionSecretKey(const crypto::SecretKey& key) = 0;

// signing
virtual void signInputKey(size_t input, const transaction_types::InputKeyInfo& info, const KeyPair& ephKeys) = 0;
Expand Down
5 changes: 4 additions & 1 deletion include/ITransfersContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <limits>
#include <vector>
#include "crypto/hash.h"
#include "IWallet.h"
#include "ITransaction.h"
#include "IObservable.h"
#include "IStreamSerializable.h"
Expand All @@ -27,7 +28,7 @@ namespace cn
crypto::PublicKey publicKey;
uint32_t blockHeight;
uint64_t timestamp;
size_t firstDepositId;
size_t firstDepositId = WALLET_INVALID_DEPOSIT_ID;
size_t depositCount = 0;
uint64_t unlockTime;
uint64_t totalAmountIn;
Expand Down Expand Up @@ -105,6 +106,8 @@ namespace cn
TransferSpent
};

virtual ~ITransfersContainer() = default;

virtual size_t transfersCount() const = 0;
virtual size_t transactionsCount() const = 0;
virtual uint64_t balance(uint32_t flags = IncludeDefault) const = 0;
Expand Down
7 changes: 3 additions & 4 deletions include/IWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct WalletTransaction
uint64_t creationTime;
uint64_t unlockTime;
std::string extra;
size_t firstDepositId = std::numeric_limits<DepositId>::max();
size_t firstDepositId = WALLET_INVALID_DEPOSIT_ID;
size_t depositCount = 0;
bool isBase;
};
Expand Down Expand Up @@ -174,7 +174,7 @@ struct DepositsInBlockInfo
class IWallet
{
public:
virtual ~IWallet() {}
virtual ~IWallet() = default;

virtual void initialize(const std::string& path, const std::string& password) = 0;
virtual void createDeposit(uint64_t amount, uint64_t term, std::string sourceAddress, std::string destinationAddress, std::string &transactionHash) = 0;
Expand All @@ -185,8 +185,7 @@ class IWallet
virtual void load(const std::string& path, const std::string& password) = 0;
virtual void shutdown() = 0;
virtual void reset(const uint64_t scanHeight) = 0;
virtual void exportWallet(const std::string& path, bool encrypt = true, WalletSaveLevel saveLevel = WalletSaveLevel::SAVE_ALL, const std::string& extra = "") = 0;
virtual void exportWalletKeys(const std::string &path, bool encrypt = true, WalletSaveLevel saveLevel = WalletSaveLevel::SAVE_KEYS_ONLY, const std::string &extra = "") = 0;
virtual void exportWallet(const std::string &path, WalletSaveLevel saveLevel, bool encrypt = true, const std::string &extra = "") = 0;

virtual void changePassword(const std::string &oldPassword, const std::string &newPassword) = 0;
virtual void save(WalletSaveLevel saveLevel = WalletSaveLevel::SAVE_ALL, const std::string& extra = "") = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/CryptoNoteConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ namespace cn
const uint32_t GENESIS_NONCE = 10000;
const uint64_t GENESIS_TIMESTAMP = 1527078920;

const uint64_t TESTNET_GENESIS_TIMESTAMP = 1632048808;

const uint8_t TRANSACTION_VERSION_1 = 1;
const uint8_t TRANSACTION_VERSION_2 = 2;
const uint8_t BLOCK_MAJOR_VERSION_1 = 1; // (Consensus I)
Expand Down
9 changes: 9 additions & 0 deletions src/CryptoNoteCore/Currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,15 @@ namespace cn
return true;
}

uint64_t Currency::getGenesisTimestamp() const
{
if (m_testnet)
{
return TESTNET_GENESIS_TIMESTAMP;
}
return GENESIS_TIMESTAMP;
}

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

CurrencyBuilder::CurrencyBuilder(logging::ILogger &log) : m_currency(log)
Expand Down
2 changes: 2 additions & 0 deletions src/CryptoNoteCore/Currency.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ namespace cn

bool validateOutput(uint64_t amount, const MultisignatureOutput &output, uint32_t height) const;

uint64_t getGenesisTimestamp() const;

private:
explicit Currency(logging::ILogger &log) : logger(log, "currency")
{
Expand Down
15 changes: 15 additions & 0 deletions src/CryptoNoteCore/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace cn {
// secret key
virtual bool getTransactionSecretKey(SecretKey& key) const override;
virtual void setTransactionSecretKey(const SecretKey& key) override;
void setDeterministicTransactionSecretKey(const SecretKey& key) override;

private:

Expand Down Expand Up @@ -237,6 +238,20 @@ namespace cn {
secretKey = key;
}

void TransactionImpl::setDeterministicTransactionSecretKey(const SecretKey& key)
{
checkIfSigning();
KeyPair deterministicTxKeys;
generateDeterministicTransactionKeys(getTransactionInputsHash(), key, deterministicTxKeys);

TransactionExtraPublicKey pk = { deterministicTxKeys.publicKey };
extra.set(pk);

transaction.extra = extra.serialize();

secretKey = deterministicTxKeys.secretKey;
}

size_t TransactionImpl::addInput(const KeyInput& input) {
checkIfSigning();
transaction.inputs.emplace_back(input);
Expand Down
64 changes: 31 additions & 33 deletions src/PaymentGate/NodeFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,65 @@ namespace payment_service {

class NodeRpcStub: public cn::INode {
public:
virtual ~NodeRpcStub() {}
virtual bool addObserver(cn::INodeObserver* observer) override { return true; }
virtual bool removeObserver(cn::INodeObserver* observer) override { return true; }

virtual void init(const Callback& callback) override { }
virtual bool shutdown() override { return true; }

virtual size_t getPeerCount() const override { return 0; }
virtual uint32_t getLastLocalBlockHeight() const override { return 0; }
virtual uint32_t getLastKnownBlockHeight() const override { return 0; }
virtual uint32_t getLocalBlockCount() const override { return 0; }
virtual uint32_t getKnownBlockCount() const override { return 0; }
virtual uint64_t getLastLocalBlockTimestamp() const override { return 0; }

virtual void relayTransaction(const cn::Transaction& transaction, const Callback& callback) override { callback(std::error_code()); }
virtual void getRandomOutsByAmounts(std::vector<uint64_t>&& amounts, uint64_t outsCount,
~NodeRpcStub() override = default;
bool addObserver(cn::INodeObserver* observer) override { return true; }
bool removeObserver(cn::INodeObserver* observer) override { return true; }

void init(const Callback& callback) override { }
bool shutdown() override { return true; }

size_t getPeerCount() const override { return 0; }
uint32_t getLastLocalBlockHeight() const override { return 0; }
uint32_t getLastKnownBlockHeight() const override { return 0; }
uint32_t getLocalBlockCount() const override { return 0; }
uint32_t getKnownBlockCount() const override { return 0; }
uint64_t getLastLocalBlockTimestamp() const override { return 0; }

void relayTransaction(const cn::Transaction& transaction, const Callback& callback) override { callback(std::error_code()); }
void getRandomOutsByAmounts(std::vector<uint64_t>&& amounts, uint64_t outsCount,
std::vector<cn::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount>& result, const Callback& callback) override {
}
virtual void getNewBlocks(std::vector<crypto::Hash>&& knownBlockIds, std::vector<cn::block_complete_entry>& newBlocks, uint32_t& startHeight, const Callback& callback) override {
void getNewBlocks(std::vector<crypto::Hash>&& knownBlockIds, std::vector<cn::block_complete_entry>& newBlocks, uint32_t& startHeight, const Callback& callback) override {
startHeight = 0;
callback(std::error_code());
}
virtual void getTransactionOutsGlobalIndices(const crypto::Hash& transactionHash, std::vector<uint32_t>& outsGlobalIndices, const Callback& callback) override { }
void getTransactionOutsGlobalIndices(const crypto::Hash& transactionHash, std::vector<uint32_t>& outsGlobalIndices, const Callback& callback) override { }

virtual void queryBlocks(std::vector<crypto::Hash>&& knownBlockIds, uint64_t timestamp, std::vector<cn::BlockShortEntry>& newBlocks,
void queryBlocks(std::vector<crypto::Hash>&& knownBlockIds, uint64_t timestamp, std::vector<cn::BlockShortEntry>& newBlocks,
uint32_t& startHeight, const Callback& callback) override {
startHeight = 0;
callback(std::error_code());
};

virtual void getPoolSymmetricDifference(std::vector<crypto::Hash>&& knownPoolTxIds, crypto::Hash knownBlockId, bool& isBcActual,
void getPoolSymmetricDifference(std::vector<crypto::Hash>&& knownPoolTxIds, crypto::Hash knownBlockId, bool& isBcActual,
std::vector<std::unique_ptr<cn::ITransactionReader>>& newTxs, std::vector<crypto::Hash>& deletedTxIds, const Callback& callback) override {
isBcActual = true;
callback(std::error_code());
}

virtual void getBlocks(const std::vector<uint32_t>& blockHeights, std::vector<std::vector<cn::BlockDetails>>& blocks,
void getBlocks(const std::vector<uint32_t>& blockHeights, std::vector<std::vector<cn::BlockDetails>>& blocks,
const Callback& callback) override { }

virtual void getBlocks(const std::vector<crypto::Hash>& blockHashes, std::vector<cn::BlockDetails>& blocks,
void getBlocks(const std::vector<crypto::Hash>& blockHashes, std::vector<cn::BlockDetails>& blocks,
const Callback& callback) override { }

virtual void getBlocks(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t blocksNumberLimit, std::vector<cn::BlockDetails>& blocks, uint32_t& blocksNumberWithinTimestamps,
void getBlocks(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t blocksNumberLimit, std::vector<cn::BlockDetails>& blocks, uint32_t& blocksNumberWithinTimestamps,
const Callback& callback) override { }

virtual void getTransactions(const std::vector<crypto::Hash>& transactionHashes, std::vector<cn::TransactionDetails>& transactions,
void getTransactions(const std::vector<crypto::Hash>& transactionHashes, std::vector<cn::TransactionDetails>& transactions,
const Callback& callback) override { }
virtual void getTransaction(const crypto::Hash &transactionHash, cn::Transaction &transaction, const Callback &callback) override {}
void getTransaction(const crypto::Hash &transactionHash, cn::Transaction &transaction, const Callback &callback) override {}

virtual void getPoolTransactions(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t transactionsNumberLimit, std::vector<cn::TransactionDetails>& transactions, uint64_t& transactionsNumberWithinTimestamps,
void getPoolTransactions(uint64_t timestampBegin, uint64_t timestampEnd, uint32_t transactionsNumberLimit, std::vector<cn::TransactionDetails>& transactions, uint64_t& transactionsNumberWithinTimestamps,
const Callback& callback) override { }

virtual void getTransactionsByPaymentId(const crypto::Hash& paymentId, std::vector<cn::TransactionDetails>& transactions,
void getTransactionsByPaymentId(const crypto::Hash& paymentId, std::vector<cn::TransactionDetails>& transactions,
const Callback& callback) override { }

virtual void getMultisignatureOutputByGlobalIndex(uint64_t amount, uint32_t gindex, cn::MultisignatureOutput& out,
void getMultisignatureOutputByGlobalIndex(uint64_t amount, uint32_t gindex, cn::MultisignatureOutput& out,
const Callback& callback) override { }

virtual void isSynchronized(bool& syncStatus, const Callback& callback) override { }
void isSynchronized(bool& syncStatus, const Callback& callback) override { }

};

Expand Down Expand Up @@ -101,11 +101,9 @@ class NodeInitObserver {
std::future<std::error_code> initFuture;
};

NodeFactory::NodeFactory() {
}
NodeFactory::NodeFactory() = default;

NodeFactory::~NodeFactory() {
}
NodeFactory::~NodeFactory() = default;

cn::INode* NodeFactory::createNode(const std::string& daemonAddress, uint16_t daemonPort) {
std::unique_ptr<cn::INode> node(new cn::NodeRpcProxy(daemonAddress, daemonPort));
Expand Down
38 changes: 26 additions & 12 deletions src/PaymentGate/PaymentServiceJsonRpcMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,59 @@
namespace payment_service
{

void Save::Request::serialize(cn::ISerializer & /*serializer*/)
void Save::Request::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void Save::Response::serialize(cn::ISerializer & /*serializer*/)
void Save::Response::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void Reset::Request::serialize(cn::ISerializer& serializer) {
serializer(viewSecretKey, "privateViewKey");
serializer(scanHeight, "scanHeight");
}

void Reset::Response::serialize(cn::ISerializer& serializer) {
void Reset::Response::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void ExportWallet::Request::serialize(cn::ISerializer &serializer)
{
serializer(exportFilename, "exportFilename");
}

void ExportWallet::Response::serialize(cn::ISerializer &serializer)
void ExportWallet::Response::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void ExportWalletKeys::Request::serialize(cn::ISerializer &serializer)
{
serializer(exportFilename, "exportFilename");
}

void ExportWalletKeys::Response::serialize(cn::ISerializer &serializer)
void ExportWalletKeys::Response::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void GetViewKey::Request::serialize(cn::ISerializer &serializer)
void GetViewKey::Request::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void GetViewKey::Response::serialize(cn::ISerializer &serializer)
{
serializer(viewSecretKey, "privateViewKey");
}

void GetStatus::Request::serialize(cn::ISerializer &serializer)
void GetStatus::Request::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void GetStatus::Response::serialize(cn::ISerializer &serializer)
Expand Down Expand Up @@ -123,8 +131,9 @@ void GetDeposit::Response::serialize(cn::ISerializer &serializer)
serializer(address, "address");
}

void GetAddresses::Request::serialize(cn::ISerializer &serializer)
void GetAddresses::Request::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void GetAddresses::Response::serialize(cn::ISerializer &serializer)
Expand Down Expand Up @@ -155,6 +164,7 @@ void CreateAddressList::Request::serialize(cn::ISerializer &serializer)
{
throw RequestSerializationError();
}
serializer(reset, "reset");
}

void CreateAddressList::Response::serialize(cn::ISerializer &serializer)
Expand All @@ -170,8 +180,9 @@ void DeleteAddress::Request::serialize(cn::ISerializer &serializer)
}
}

void DeleteAddress::Response::serialize(cn::ISerializer &serializer)
void DeleteAddress::Response::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void GetSpendKeys::Request::serialize(cn::ISerializer &serializer)
Expand Down Expand Up @@ -442,8 +453,9 @@ void CreateDelayedTransaction::Response::serialize(cn::ISerializer &serializer)
serializer(transactionHash, "transactionHash");
}

void GetDelayedTransactionHashes::Request::serialize(cn::ISerializer &serializer)
void GetDelayedTransactionHashes::Request::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void GetDelayedTransactionHashes::Response::serialize(cn::ISerializer &serializer)
Expand All @@ -459,8 +471,9 @@ void DeleteDelayedTransaction::Request::serialize(cn::ISerializer &serializer)
}
}

void DeleteDelayedTransaction::Response::serialize(cn::ISerializer &serializer)
void DeleteDelayedTransaction::Response::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void SendDelayedTransaction::Request::serialize(cn::ISerializer &serializer)
Expand All @@ -471,8 +484,9 @@ void SendDelayedTransaction::Request::serialize(cn::ISerializer &serializer)
}
}

void SendDelayedTransaction::Response::serialize(cn::ISerializer &serializer)
void SendDelayedTransaction::Response::serialize(const cn::ISerializer &) const
{
// Nothing to do here.
}

void GetMessagesFromExtra::Request::serialize(cn::ISerializer &serializer)
Expand Down
Loading