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

Banking features to concealwallet #281

Merged
merged 50 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a637768
Withdraw deposit without vector
cartoon-face Feb 19, 2022
984f8f3
List wallet deposits
cartoon-face Feb 19, 2022
c07834c
Deposit CCX function
cartoon-face Feb 19, 2022
3da34bd
Withdraw CCX function
cartoon-face Feb 19, 2022
89d21ba
Merge branch 'ConcealNetwork:master' into feat-banking
cartoon-face Feb 21, 2022
c606cd1
Confirm deposit
cartoon-face Feb 21, 2022
c009c7c
Missing semi-colon
cartoon-face Feb 21, 2022
0fe420e
Remove do while true
cartoon-face Feb 27, 2022
6209c34
Update confirm deposit function
cartoon-face Feb 28, 2022
1c54517
Stray brace
cartoon-face Feb 28, 2022
c5cb645
Trigger rebuild for tests
cartoon-face Feb 28, 2022
cc170ba
Update deposit command
cartoon-face Mar 1, 2022
61c5520
Fix hash output
cartoon-face Mar 1, 2022
b783465
Remove possible infinate loop
cartoon-face Mar 3, 2022
ce56316
List actual deposit info, not the tx that made the deposit
cartoon-face Mar 7, 2022
628a9ef
Adjust `list_deposits` output
cartoon-face Mar 12, 2022
9994e62
Don't overthink it man.
cartoon-face Mar 25, 2022
e911539
Store deposit height & unlockHeight when inserting new deposit
cartoon-face Mar 27, 2022
9567b81
Update output for list_deposits
cartoon-face Mar 27, 2022
54c2230
Store deposit height & unlockHeight when doing multisig tx
cartoon-face Mar 27, 2022
f8ee2db
Store deposit height and use that to calculate interest
cartoon-face Mar 27, 2022
1a843ea
Serialize and add deposit to Legacy
cartoon-face Mar 29, 2022
65d6a8d
Deposit changes
cartoon-face Mar 29, 2022
d4427d0
Clear deposits on reset
cartoon-face Mar 29, 2022
771e748
Serialise height & unlockHeight
cartoon-face Mar 29, 2022
31ee9c5
Update v1 serializer
cartoon-face Mar 29, 2022
75ef183
Trigger rebuild
cartoon-face Mar 29, 2022
7008bcf
Add height to tx context & deposit request
cartoon-face Mar 30, 2022
651ca92
Touchups
cartoon-face Apr 2, 2022
5fef87f
Cleanup
cartoon-face Apr 3, 2022
bd79108
Remove deposits from serialisation v1
cartoon-face Apr 5, 2022
206afda
Print deposit balances
cartoon-face Apr 6, 2022
3c4416d
Keep support for GUI
cartoon-face Apr 8, 2022
4df5ef0
Use same logic for unlockHeight
cartoon-face Apr 9, 2022
86307e5
Don't use context, always use txInfo for height
cartoon-face Apr 11, 2022
5a65043
Get deposit height from the transaction that made the deposit
cartoon-face Apr 13, 2022
50159de
Update deposit info
cartoon-face Apr 13, 2022
2d64148
Trigger rebuild
cartoon-face Apr 13, 2022
dbb9c0b
Update SimpleWallet.cpp
cartoon-face Apr 17, 2022
7d26351
Get TX from deposits creating ID
cartoon-face Apr 28, 2022
7fc0a84
Use same logic here
cartoon-face Apr 28, 2022
ab8523d
Merge branch 'development' into feat-banking
krypt0x May 23, 2022
4b2a70d
Account for deposit balances in `show_balance`
cartoon-face May 26, 2022
1ab0a2d
Revert requested
cartoon-face May 31, 2022
813af26
Missing semi
cartoon-face May 31, 2022
d33f70d
Remove height from deposit request
cartoon-face Jun 2, 2022
0c701c1
Remove height from make deposit request
cartoon-face Jun 2, 2022
f2fabc0
Make help & ext_help stand out
cartoon-face Jun 7, 2022
f0a9e14
Remove optional arg message
cartoon-face Jun 7, 2022
acbe694
Use TxInfo for unlock height using tx height + deposit term
cartoon-face Jun 7, 2022
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.0)

include(CheckCXXCompilerFlag)
set(VERSION "6.6.3")

set(VERSION_BUILD_NO "Ataegina")
# Packaged from main commits
set(COMMIT 1db6e66)
Expand Down
4 changes: 4 additions & 0 deletions include/IWalletLegacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class IWalletLegacyObserver {
virtual void externalTransactionCreated(TransactionId transactionId) {}
virtual void sendTransactionCompleted(TransactionId transactionId, std::error_code result) {}
virtual void transactionUpdated(TransactionId transactionId) {}
virtual void depositUpdated(const DepositId& depositId) {}
virtual void depositsUpdated(const std::vector<DepositId>& depositIds) {}
};

Expand Down Expand Up @@ -152,8 +153,11 @@ class IWalletLegacy {
virtual std::list<TransactionOutputInformation> selectFusionTransfersToSend(uint64_t threshold, size_t minInputCount, size_t maxInputCount) = 0;
virtual TransactionId sendFusionTransaction(const std::list<TransactionOutputInformation>& fusionInputs, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) = 0;
virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t mixIn = 0) = 0;
virtual TransactionId withdrawDeposit(const DepositId& depositId, uint64_t fee) = 0;
virtual TransactionId withdrawDeposits(const std::vector<DepositId>& depositIds, uint64_t fee) = 0;
virtual std::error_code cancelTransaction(size_t transferId) = 0;
virtual Deposit get_deposit(DepositId depositId) = 0;


};

Expand Down
9 changes: 9 additions & 0 deletions src/Common/StringTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,14 @@ std::string timeIntervalToString(uint64_t intervalInSeconds) {
".s" + std::to_string(seconds);
}

std::string makeCenteredString(size_t width, const std::string& text) {
if (text.size() >= width) {
return text;
}

size_t offset = (width - text.size() + 1) / 2;
return std::string(offset, ' ') + text + std::string(width - text.size() - offset, ' ');
}


}
4 changes: 3 additions & 1 deletion src/Common/StringTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ bool parseIpAddressAndPort(uint32_t& ip, uint32_t& port, const std::string& addr

std::string timeIntervalToString(uint64_t intervalInSeconds);

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

}
119 changes: 119 additions & 0 deletions src/SimpleWallet/DepositHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include <sstream>
#include <string>

#include "DepositHelper.h"

#include "CryptoNoteConfig.h"

#include "Common/StringTools.h"

namespace cn
{
uint32_t deposit_helper::deposit_term(cn::Deposit deposit)
{
return deposit.term;
}

std::string deposit_helper::deposit_amount(cn::Deposit deposit, const Currency& currency)
{
return currency.formatAmount(deposit.amount);
}

std::string deposit_helper::deposit_interest(cn::Deposit deposit, const Currency& currency)
{
return currency.formatAmount(deposit.interest);
}

std::string deposit_helper::deposit_status(cn::Deposit deposit)
{
std::string status_str = "";

if (deposit.locked)
status_str = "Locked";
else if (deposit.spendingTransactionId == cn::WALLET_LEGACY_INVALID_TRANSACTION_ID)
status_str = "Unlocked";
else
status_str = "Spent";

return status_str;
}

size_t deposit_helper::deposit_creating_tx_id(cn::Deposit deposit)
{
return deposit.creatingTransactionId;
}

size_t deposit_helper::deposit_spending_tx_id(cn::Deposit deposit)
{
return deposit.spendingTransactionId;
}

uint64_t deposit_helper::deposit_unlock_height(cn::Deposit deposit)
{
return deposit.unlockHeight;
}

uint64_t deposit_helper::deposit_height(cn::WalletLegacyTransaction txInfo)
{
return txInfo.blockHeight;
}

std::string deposit_helper::get_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo)
{
std::string unlock_str = "";
uint64_t actual_unlock_height = deposit_height(txInfo) + deposit_term(deposit);

bool bad_unlock = actual_unlock_height > cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER;
if (bad_unlock)
unlock_str = "Please wait.";
else
unlock_str = std::to_string(actual_unlock_height);

bool bad_unlock2 = unlock_str == "0";
if (bad_unlock2)
unlock_str = "ERROR";

std::stringstream full_info;

full_info << std::left <<
std::setw(8) << common::makeCenteredString(8, std::to_string(did)) << " | " <<
std::setw(20) << common::makeCenteredString(20, deposit_amount(deposit, currency)) << " | " <<
std::setw(20) << common::makeCenteredString(20, deposit_interest(deposit, currency)) << " | " <<
std::setw(16) << common::makeCenteredString(16, unlock_str) << " | " <<
std::setw(10) << common::makeCenteredString(10, deposit_status(deposit));

std::string as_str = full_info.str();

return as_str;
}

std::string deposit_helper::get_full_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo)
{
std::string unlock_str = "";
uint64_t actual_unlock_height = deposit_height(txInfo) + deposit_term(deposit);

bool bad_unlock = actual_unlock_height > cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER;
if (bad_unlock)
unlock_str = "Please wait.";
else
unlock_str = std::to_string(actual_unlock_height);

bool bad_unlock2 = unlock_str == "0";
if (bad_unlock2)
unlock_str = "ERROR";

std::stringstream full_info;

full_info <<
"ID: " << std::to_string(did) << "\n" <<
"Amount: " << deposit_amount(deposit, currency) << "\n" <<
"Interest: " << deposit_interest(deposit, currency) << "\n" <<
"Height: " << deposit_height(txInfo) << "\n" <<
"Unlock Height: " << unlock_str << "\n" <<
"Status: " << deposit_status(deposit) << "\n";

std::string as_str = full_info.str();

return as_str;
}
}
83 changes: 83 additions & 0 deletions src/SimpleWallet/DepositHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@



#include <string>

#include "IWalletLegacy.h"

#include "CryptoNoteCore/Currency.h"

namespace cn
{
class deposit_helper
{
public:
/**
* @param deposit - obtain information from deposit
* @return - returns deposit term, should be multiple of 21900
**/
uint32_t deposit_term(cn::Deposit deposit);

/**
* @param deposit - obtain information from deposit
* @param currency - format output amount
* @return - returns deposit amount as string
**/
std::string deposit_amount(cn::Deposit deposit, const Currency& currency);

/**
* @param deposit - obtain information from deposit
* @param currency - format output amount
* @return - returns deposit interest based of amount and term as string
**/
std::string deposit_interest(cn::Deposit deposit, const Currency& currency);

/**
* @param deposit - obtain information from deposit
* @return - "Locked", "Unlocked" or "Spent" depending on state of deposit
**/
std::string deposit_status(cn::Deposit deposit);

/**
* @param deposit - obtain information from deposit
* @return - returns deposit creatingTransactionId
**/
size_t deposit_creating_tx_id(cn::Deposit deposit);

/**
* @param deposit - obtain information from deposit
* @return - returns deposit spendingTransactionId
**/
size_t deposit_spending_tx_id(cn::Deposit deposit);

/**
* @param deposit - obtain information from deposit
* @return - returns unlock height from height deposited + term
**/
uint64_t deposit_unlock_height(cn::Deposit deposit);

/**
* @param txInfo - obtain height from transaction
* @return - returns deposit height
**/
uint64_t deposit_height(cn::WalletLegacyTransaction txInfo);

/**
* @param deposit - obtain information from deposit
* @param did - id to search deposit
* @param currency - used to supply amount and interest
* @param txInfo - obtain height from transaction
* @return - returns deposit info string in single row style
**/
std::string get_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo);

/**
* @param deposit - obtain information from deposit
* @param did - id to search deposit
* @param currency - used to supply amount and interest
* @param txInfo - obtain height from transaction
* @return - returns full deposit info string
**/
std::string get_full_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo);
};
}
Loading