Skip to content

Commit

Permalink
Merge pull request #329 from ConcealNetwork/legacy-green
Browse files Browse the repository at this point in the history
Replace WalletLegacy with WalletGreen
  • Loading branch information
AxVultis authored Feb 22, 2024
2 parents 4b48c6a + 2fc8818 commit f732e9d
Show file tree
Hide file tree
Showing 31 changed files with 1,287 additions and 1,101 deletions.
10 changes: 6 additions & 4 deletions include/ITransfersSynchronizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ITransfersSubscription;

class ITransfersObserver {
public:
virtual ~ITransfersObserver() = default;
virtual void onError(ITransfersSubscription* object,
uint32_t height, std::error_code ec) {
}
Expand All @@ -53,25 +54,26 @@ class ITransfersObserver {

class ITransfersSubscription : public IObservable < ITransfersObserver > {
public:
virtual ~ITransfersSubscription() {}
virtual ~ITransfersSubscription() = default;

virtual AccountPublicAddress getAddress() = 0;
virtual ITransfersContainer& getContainer() = 0;
};

class ITransfersSynchronizerObserver {
public:
virtual ~ITransfersSynchronizerObserver() = default;
virtual void onBlocksAdded(const crypto::PublicKey& viewPublicKey, const std::vector<crypto::Hash>& blockHashes) {}
virtual void onBlockchainDetach(const crypto::PublicKey& viewPublicKey, uint32_t blockIndex) {}
virtual void onTransactionDeleteBegin(const crypto::PublicKey& viewPublicKey, crypto::Hash transactionHash) {}
virtual void onTransactionDeleteEnd(const crypto::PublicKey& viewPublicKey, crypto::Hash transactionHash) {}
virtual void onTransactionDeleteBegin(const crypto::PublicKey &viewPublicKey, const crypto::Hash &transactionHash) {}
virtual void onTransactionDeleteEnd(const crypto::PublicKey &viewPublicKey, const crypto::Hash &transactionHash) {}
virtual void onTransactionUpdated(const crypto::PublicKey& viewPublicKey, const crypto::Hash& transactionHash,
const std::vector<ITransfersContainer*>& containers) {}
};

class ITransfersSynchronizer : public IStreamSerializable {
public:
virtual ~ITransfersSynchronizer() {}
virtual ~ITransfersSynchronizer() = default;

virtual ITransfersSubscription& addSubscription(const AccountSubscription& acc) = 0;
virtual bool removeSubscription(const AccountPublicAddress& acc) = 0;
Expand Down
53 changes: 50 additions & 3 deletions include/IWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@

#include <limits>
#include <string>
#include <system_error>
#include <vector>
#include <boost/optional.hpp>
#include "CryptoNote.h"
#include "CryptoNoteConfig.h"
#include "IObservable.h"

namespace cn
{

typedef size_t DepositId;
using DepositId = size_t;
using TransactionId = size_t;

const size_t WALLET_INVALID_TRANSACTION_ID = std::numeric_limits<size_t>::max();
const size_t WALLET_INVALID_TRANSFER_ID = std::numeric_limits<size_t>::max();
Expand Down Expand Up @@ -104,6 +107,7 @@ struct WalletTransaction
size_t firstDepositId = WALLET_INVALID_DEPOSIT_ID;
size_t depositCount = 0;
bool isBase;
std::vector<std::string> messages;
};

enum class WalletTransferType : uint8_t
Expand Down Expand Up @@ -151,6 +155,7 @@ struct TransactionParameters
uint64_t unlockTimestamp = 0;
DonationSettings donation;
std::string changeDestination;
uint64_t ttl = 0;
};

struct WalletTransactionWithTransfers
Expand All @@ -171,16 +176,48 @@ struct DepositsInBlockInfo
std::vector<Deposit> deposits;
};

class IWallet
struct PaymentIdTransactions
{
crypto::Hash paymentId;
std::vector<WalletTransaction> transactions;
};

class TransactionOutputInformation;
class IBlockchainSynchronizerObserver;

class IWalletObserver
{
public:
virtual ~IWalletObserver() = default;

virtual void initCompleted(std::error_code result) = 0;
virtual void saveCompleted(std::error_code result) = 0;
virtual void synchronizationProgressUpdated(uint32_t current, uint32_t total) = 0;
virtual void synchronizationCompleted(std::error_code result) = 0;
virtual void actualBalanceUpdated(uint64_t balance) = 0;
virtual void pendingBalanceUpdated(uint64_t balance) = 0;
virtual void actualDepositBalanceUpdated(uint64_t balance) = 0;
virtual void pendingDepositBalanceUpdated(uint64_t balance) = 0;
virtual void actualInvestmentBalanceUpdated(uint64_t balance) = 0;
virtual void pendingInvestmentBalanceUpdated(uint64_t balance) = 0;
virtual void externalTransactionCreated(TransactionId transactionId) = 0;
virtual void sendTransactionCompleted(TransactionId transactionId, std::error_code result) = 0;
virtual void transactionUpdated(TransactionId transactionId) = 0;
virtual void depositUpdated(DepositId depositId) = 0;
virtual void depositsUpdated(const std::vector<DepositId> &depositIds) = 0;
};

class IWallet : public IObservable<IWalletObserver>
{
public:
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;
virtual void createDeposit(uint64_t amount, uint32_t term, std::string sourceAddress, std::string destinationAddress, std::string &transactionHash) = 0;
virtual void withdrawDeposit(DepositId depositId, std::string &transactionHash) = 0;
virtual Deposit getDeposit(size_t depositIndex) const = 0;
virtual void initializeWithViewKey(const std::string& path, const std::string& password, const crypto::SecretKey& viewSecretKey) = 0;
virtual void generateNewWallet(const std::string &path, const std::string &password) = 0;
virtual void load(const std::string& path, const std::string& password, std::string& extra) = 0;
virtual void load(const std::string& path, const std::string& password) = 0;
virtual void shutdown() = 0;
Expand Down Expand Up @@ -210,6 +247,8 @@ class IWallet
virtual uint64_t getActualBalance(const std::string &address) const = 0;
virtual uint64_t getPendingBalance() const = 0;
virtual uint64_t getPendingBalance(const std::string &address) const = 0;
virtual uint64_t getDustBalance() const = 0;
virtual uint64_t getDustBalance(const std::string &address) const = 0;

virtual uint64_t getLockedDepositBalance() const = 0;
virtual uint64_t getLockedDepositBalance(const std::string &address) const = 0;
Expand Down Expand Up @@ -239,6 +278,14 @@ class IWallet
virtual void commitTransaction(size_t transactionId) = 0;
virtual void rollbackUncommitedTransaction(size_t transactionId) = 0;

virtual std::vector<TransactionOutputInformation> getUnspentOutputs() = 0;
virtual size_t getUnspentOutputsCount() = 0;
virtual std::string getReserveProof(const std::string &address, const uint64_t &reserve, const std::string &message) = 0;
virtual bool getTxProof(const crypto::Hash &transactionHash, const cn::AccountPublicAddress &address, const crypto::SecretKey &tx_key, std::string &signature) = 0;
virtual crypto::SecretKey getTransactionDeterministicSecretKey(crypto::Hash &transactionHash) const = 0;
virtual size_t createOptimizationTransaction(const std::string &address) = 0;
virtual std::vector<PaymentIdTransactions> getTransactionsByPaymentIds(const std::vector<crypto::Hash> &paymentIds) = 0;

virtual void start() = 0;
virtual void stop() = 0;

Expand Down
6 changes: 6 additions & 0 deletions src/Common/CommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ namespace command_line
return !value.empty();
}

template <typename T, bool required>
bool has_arg_2(const boost::program_options::variables_map &vm, const arg_descriptor<T, required> &arg)
{
auto value = vm[arg.name];
return !value.empty() && !value.defaulted();
}

template<typename T, bool required>
T get_arg(const boost::program_options::variables_map& vm, const arg_descriptor<T, required>& arg)
Expand Down
2 changes: 1 addition & 1 deletion src/Common/FileMappedVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ void FileMappedVector<T>::rename(const std::string& newPath) {
template<class T>
template<class F>
void FileMappedVector<T>::atomicUpdate(F&& func) {
atomicUpdate0(capacity(), prefixSize(), suffixSize(), std::forward(func));
atomicUpdate0(capacity(), prefixSize(), suffixSize(), std::move(func));
}

template<class T>
Expand Down
15 changes: 14 additions & 1 deletion src/Common/StringTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "StringTools.h"
#include <fstream>
#include <ctime>

namespace common {

Expand Down Expand Up @@ -348,5 +349,17 @@ std::string makeCenteredString(size_t width, const std::string& text) {
return std::string(offset, ' ') + text + std::string(width - text.size() - offset, ' ');
}


std::string formatTimestamp(time_t timestamp)
{
std::string buffer(32, '\0');
struct tm time_info;
#ifdef _WIN32
gmtime_s(&time_info, &timestamp);
#else
gmtime_r(&timestamp, &time_info);
#endif
std::strftime(&buffer[0], buffer.size(), "%c", &time_info);
buffer += " UTC";
return buffer;
}
}
2 changes: 2 additions & 0 deletions src/Common/StringTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ std::string timeIntervalToString(uint64_t intervalInSeconds);

std::string makeCenteredString(size_t width, const std::string& text);

std::string formatTimestamp(time_t timestamp);

}
Loading

0 comments on commit f732e9d

Please sign in to comment.