Skip to content

Commit

Permalink
Merge pull request #252 from VanGrx/master
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
VanGrx authored Feb 6, 2021
2 parents c4e5d8c + 36a0d7b commit 6314563
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ src/cryptonote_core/protobuf/*.pb.h

# QT creator files
*.user


# KDev files
*.kdev4
6 changes: 3 additions & 3 deletions src/checkpoints/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ namespace cryptonote

//todo setup safexpulse infrastructure
static const std::vector<std::string> dns_urls = {
""

};

static const std::vector<std::string> testnet_dns_urls = {
""

};

static const std::vector<std::string> stagenet_dns_urls = {
""

};

if (!tools::dns_utils::load_txt_records_from_dns(records, nettype == TESTNET ? testnet_dns_urls : nettype == STAGENET ? stagenet_dns_urls : dns_urls))
Expand Down
8 changes: 4 additions & 4 deletions src/common/updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ namespace tools

// All four SafexPulse domains have DNSSEC on and valid
static const std::vector<std::string> dns_urls = {
"updates.safexpulse.org",
"updates.safexpulse.net",
"updates.safexpulse.co",
"updates.safexpulse.se"
// "updates.safexpulse.org",
// "updates.safexpulse.net",
// "updates.safexpulse.co",
// "updates.safexpulse.se"
};

if (!tools::dns_utils::load_txt_records_from_dns(records, dns_urls))
Expand Down
4 changes: 2 additions & 2 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,8 @@ simple_wallet::simple_wallet()

m_cmd_binder.set_handler("unstake_token",
boost::bind(&simple_wallet::unstake_token, this, _1),
tr("unstake_token [index=<N1>] [<priority>] <address> <token_amount> [<payment_id>]"),
tr("Unstake <token_amount> with <address> as staked tokens holder, optionally set payment_id, priority, and subaddress index"));
tr("unstake_token [index=<N1>] [<priority>] <address> <token_amount> [<staked_tokens_height>] [<payment_id>]"),
tr("Unstake <token_amount> with <address> as staked tokens holder, optionally set block height of tokens You want to unstake, payment_id, priority, and subaddress index"));

m_cmd_binder.set_handler("safex_purchase",
boost::bind(&simple_wallet::safex_purchase, this, _1),
Expand Down
37 changes: 24 additions & 13 deletions src/simplewallet/simplewallet_safex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,22 @@ namespace cryptonote
}
}

if (!r)
if (!r && command_type != CommandType::TransferUnstakeToken)
{
fail_msg_writer() << tr("payment id has invalid format, expected 16 or 64 character hex string: ") << payment_id_str;
return true;
}
payment_id_seen = true;
if(r)
payment_id_seen = true;
else
local_args.push_back(payment_id_str);
}
uint64_t safex_network_fee = 0;

vector<cryptonote::tx_destination_entry> dsts;

uint64_t staked_token_height = 0;

safex::safex_account my_safex_account = AUTO_VAL_INIT(my_safex_account);
if (command_type == CommandType::TransferCreateAccount || command_type == CommandType::TransferEditAccount) {
//use my own current subaddress as destination
Expand Down Expand Up @@ -548,19 +553,17 @@ namespace cryptonote
else
{

for (size_t i = 0; i < local_args.size(); i += 2)
{
cryptonote::address_parse_info info = AUTO_VAL_INIT(info);
cryptonote::tx_destination_entry de = AUTO_VAL_INIT(de);

if (command_type == CommandType::TransferDonation)
{
//use my own address as destination
std::string destination_addr = m_wallet->get_subaddress_as_str({m_current_subaddress_account, 0});
local_args.insert(local_args.begin() + i, destination_addr);
local_args.insert(local_args.begin(), destination_addr);
}

if (!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[i], oa_prompter))
if (!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[0], oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
return true;
Expand All @@ -572,7 +575,7 @@ namespace cryptonote
{
if (payment_id_seen)
{
fail_msg_writer() << tr("a single transaction cannot use more than one payment id: ") << local_args[i];
fail_msg_writer() << tr("a single transaction cannot use more than one payment id: ") << local_args[0];
return true;
}

Expand All @@ -589,10 +592,10 @@ namespace cryptonote

uint64_t value_amount = 0;

bool ok = cryptonote::parse_amount(value_amount, local_args[i + 1]);
bool ok = cryptonote::parse_amount(value_amount, local_args[1]);
if (!ok || 0 == value_amount)
{
fail_msg_writer() << tr("amount is wrong: ") << local_args[i] << ' ' << local_args[i + 1] <<
fail_msg_writer() << tr("amount is wrong: ") << local_args[1] << ' ' << local_args[1] <<
", " << tr("expected number from 0 to ") << print_money(std::numeric_limits<uint64_t>::max());
return true;
}
Expand All @@ -602,7 +605,7 @@ namespace cryptonote
{
if (!tools::is_whole_token_amount(value_amount))
{
fail_msg_writer() << tr("token amount must be whole number. ") << local_args[i] << ' ' << local_args[i + 1];
fail_msg_writer() << tr("token amount must be whole number. ") << local_args[0] << ' ' << local_args[1];
return true;
}

Expand All @@ -620,9 +623,18 @@ namespace cryptonote
{
if (!tools::is_whole_token_amount(value_amount))
{
fail_msg_writer() << tr("token amount must be whole number. ") << local_args[i] << ' ' << local_args[i + 1];
fail_msg_writer() << tr("token amount must be whole number. ") << local_args[0] << ' ' << local_args[1];
return true;
}

if(local_args.size() > 2){
if (!epee::string_tools::get_xtype_from_string(staked_token_height, local_args[2])){
fail_msg_writer() << tr("Bad staked tokens height given!!!");
return true;
}
}


de.token_amount = value_amount;
de.script_output = false;
de.output_type = tx_out_type::out_token;
Expand All @@ -635,7 +647,6 @@ namespace cryptonote
// Allow to collect outputs for regular SFX transaction.

dsts.push_back(de);
}
}

// If its demo purchase, make special destination_entry for network fee.
Expand Down Expand Up @@ -720,7 +731,7 @@ namespace cryptonote



ptx_vector = m_wallet->create_transactions_advanced(command, dsts, fake_outs_count, unlock_block, priority, extra, m_current_subaddress_account, subaddr_indices, m_trusted_daemon, my_safex_account);
ptx_vector = m_wallet->create_transactions_advanced(command, dsts, fake_outs_count, unlock_block, priority, extra, m_current_subaddress_account, subaddr_indices, m_trusted_daemon, my_safex_account, staked_token_height);



Expand Down
8 changes: 6 additions & 2 deletions src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,8 @@ PendingTransaction * WalletImpl::createAdvancedTransaction(const string &dst_add

uint32_t adjusted_priority = m_wallet->adjust_priority(static_cast<uint32_t>(priority));

uint64_t staked_token_height = 0;

PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);

do {
Expand Down Expand Up @@ -1920,14 +1922,16 @@ PendingTransaction * WalletImpl::createAdvancedTransaction(const string &dst_add
}
else if(advancedCommnand.m_transaction_type == TransactionType::UnstakeTokenTransaction) {

Safex::UnstakeTokenCommand stakeToken = static_cast<Safex::UnstakeTokenCommand &>(advancedCommnand);
Safex::UnstakeTokenCommand unstakeToken = static_cast<Safex::UnstakeTokenCommand &>(advancedCommnand);
if (!tools::is_whole_token_amount(*value_amount))
{
m_status = Status_Error;
m_errorString = tr("Token amount must be whole number.");
break;
}

staked_token_height = unstakeToken.m_height;

de.addr = info.address;
de.is_subaddress = info.is_subaddress;
de.token_amount = *value_amount;
Expand Down Expand Up @@ -2094,7 +2098,7 @@ PendingTransaction * WalletImpl::createAdvancedTransaction(const string &dst_add
command = safex::command_t::create_feedback;
}

transaction->m_pending_tx = m_wallet->create_transactions_advanced(command, dsts, fake_outs_count, unlock_block, priority, extra, subaddr_account, subaddr_indices, m_trustedDaemon, my_safex_account);
transaction->m_pending_tx = m_wallet->create_transactions_advanced(command, dsts, fake_outs_count, unlock_block, priority, extra, subaddr_account, subaddr_indices, m_trustedDaemon, my_safex_account, staked_token_height);

} catch (const tools::error::daemon_busy&) {
// TODO: make it translatable with "tr"?
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/api/wallet_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ struct UnstakeTokenCommand : public AdvancedCommand
{
public:
UnstakeTokenCommand():AdvancedCommand{TransactionType::UnstakeTokenTransaction}{}
UnstakeTokenCommand(const std::string& _address, const uint64_t _token_amount):AdvancedCommand{TransactionType::UnstakeTokenTransaction},m_token_amount{_token_amount},m_address{_address}{}
UnstakeTokenCommand(const std::string& _address, const uint64_t _token_amount, const uint64_t _height = 0):AdvancedCommand{TransactionType::UnstakeTokenTransaction},m_token_amount{_token_amount},m_address{_address},m_height{_height}{}

uint64_t m_token_amount;
std::string m_address;
uint64_t m_height;
};

struct CreatePricePegCommand : public AdvancedCommand
Expand Down
64 changes: 53 additions & 11 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4573,16 +4573,58 @@ size_t wallet::pop_ideal_value(std::vector<size_t> &unused_indices, const std::v
return pop_ideal_value_from(m_transfers, unused_indices, selected_transfers, out_type, cash_amount, token_amount);
}
//----------------------------------------------------------------------------------------------------
size_t wallet::pop_advanced_output(const std::vector<size_t>& selected_transfers, const std::vector<uint8_t> &acc_username, const cryptonote::tx_out_type out_type) const
{
const std::string acc_username_str(acc_username.begin(), acc_username.end());
return pop_advanced_output_from(m_transfers, selected_transfers, acc_username_str, out_type);
}
size_t wallet::pop_advanced_output(const std::vector<size_t>& selected_transfers, const std::vector<uint8_t> &acc_username, const cryptonote::tx_out_type out_type) const
{
const std::string acc_username_str(acc_username.begin(), acc_username.end());
return pop_advanced_output_from(m_transfers, selected_transfers, acc_username_str, out_type);
}

size_t wallet::pop_advanced_output(const std::vector<size_t>& selected_transfers, const crypto::hash& out_id, const cryptonote::tx_out_type out_type) const
size_t wallet::pop_advanced_output(const std::vector<size_t>& selected_transfers, const crypto::hash& out_id, const cryptonote::tx_out_type out_type) const
{
return pop_advanced_output_from(m_transfers, selected_transfers, out_id, out_type);
}


size_t wallet::pop_selected_stake_token_value(std::vector<size_t> &unused_indices, const std::vector<size_t>& selected_transfers, const cryptonote::tx_out_type out_type, const uint64_t cash_amount, const uint64_t token_amount, const uint64_t staked_token_height) const
{

std::vector<size_t> candidates;
uint64_t oldest_output = get_blockchain_current_height();
for (size_t n = 0; n < unused_indices.size(); ++n)
{
return pop_advanced_output_from(m_transfers, selected_transfers, out_id, out_type);
const transfer_details &candidate = m_transfers[unused_indices[n]];
if ((candidate.get_out_type() != out_type) || (candidate.token_amount() != token_amount) || (candidate.amount() != cash_amount)) continue;

//in case of staked token outputs with the same amount, select the oldest one
if (candidate.get_out_type() == tx_out_type::out_staked_token)
{

if (staked_token_height == 0 && candidate.m_block_height < oldest_output)
{
candidates.clear();
oldest_output = candidate.m_block_height;
candidates.push_back(n);
}
else if (staked_token_height == candidate.m_block_height)
{
candidates.clear();
oldest_output = candidate.m_block_height;
candidates.push_back(n);
break;
}
}
}


THROW_WALLET_EXCEPTION_IF(candidates.empty(), error::no_matching_available_outputs);

size_t idx;
idx = crypto::rand<size_t>() % candidates.size();

return pop_index(unused_indices, candidates[idx]);

}

//----------------------------------------------------------------------------------------------------
// Select random input sources for transaction.
// returns:
Expand Down Expand Up @@ -8738,7 +8780,7 @@ std::vector<wallet::pending_tx> wallet::create_transactions_migration(

std::vector<wallet::pending_tx> wallet::create_transactions_advanced(safex::command_t command_type, std::vector<cryptonote::tx_destination_entry> dsts,
const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> &extra,
uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, bool trusted_daemon, const safex::safex_account &sfx_acc)
uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, bool trusted_daemon, const safex::safex_account &sfx_acc, const uint64_t staked_token_height)
{
//ensure device is let in NONE mode in any case
hw::device &hwdev = m_account.get_device();
Expand Down Expand Up @@ -9189,7 +9231,7 @@ std::vector<wallet::pending_tx> wallet::create_transactions_advanced(safex::comm
std::vector<size_t> indices;

if (dsts[0].output_type == tx_out_type::out_staked_token)
idx = pop_ideal_value(indices, tx.selected_transfers, dsts[0].output_type, dsts[0].amount, dsts[0].token_amount);
idx = pop_selected_stake_token_value(indices, tx.selected_transfers, dsts[0].output_type, dsts[0].amount, dsts[0].token_amount, staked_token_height);
else
idx = pop_best_value(indices, tx.selected_transfers, true, dsts[0].output_type);

Expand Down Expand Up @@ -9294,7 +9336,7 @@ std::vector<wallet::pending_tx> wallet::create_transactions_advanced(safex::comm
{
if (needed_staked_tokens > 0)
{
idx = pop_ideal_value(*unused_staked_token_transfers_indices, tx.selected_transfers, tx_out_type::out_staked_token, 0, needed_staked_tokens);
idx = pop_selected_stake_token_value(*unused_staked_token_transfers_indices, tx.selected_transfers, tx_out_type::out_staked_token, 0, needed_staked_tokens, staked_token_height);
}
else if (needed_tokens > 0)
{
Expand Down Expand Up @@ -12286,7 +12328,7 @@ uint64_t wallet::get_segregation_fork_height() const
{
//todo Setup this for Safex
static const std::vector<std::string> dns_urls = {
"segheights.safex.org",
// "segheights.safex.org",
};

const uint64_t current_height = get_blockchain_current_height();
Expand Down
4 changes: 3 additions & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ namespace tools
std::vector<size_t> unused_transfers_indices, std::vector<size_t> unused_dust_indices, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority,
const std::vector<uint8_t> &extra, bool trusted_daemon);
std::vector<wallet::pending_tx> create_transactions_migration(std::vector<cryptonote::tx_destination_entry> dsts, crypto::hash bitcoin_transaction_hash, uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra, bool trusted_daemon, bool mark_as_spent=false);
std::vector<wallet::pending_tx> create_transactions_advanced(safex::command_t command_type, std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, bool trusted_daemon, const safex::safex_account &sfx_acc = safex::safex_account{});
std::vector<wallet::pending_tx> create_transactions_advanced(safex::command_t command_type, std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, bool trusted_daemon, const safex::safex_account &sfx_acc = safex::safex_account{}, const uint64_t staked_token_height = 0);
std::vector<pending_tx> create_unmixable_sweep_transactions(bool trusted_daemon, cryptonote::tx_out_type out_type);
bool check_connection(uint32_t *version = NULL, uint32_t timeout = 200000);
void get_transfers(wallet::transfer_container& incoming_transfers) const;
Expand Down Expand Up @@ -945,6 +945,8 @@ namespace tools
size_t pop_advanced_output(const std::vector<size_t>& selected_transfers, const std::vector<uint8_t> &acc_username, const cryptonote::tx_out_type out_type) const;
size_t pop_advanced_output(const std::vector<size_t>& selected_transfers, const crypto::hash& out_id, const cryptonote::tx_out_type out_type) const;
size_t pop_advanced_output_from(const transfer_container &transfers, const std::vector<size_t>& selected_transfers, const crypto::hash& out_id, const cryptonote::tx_out_type out_type) const;
size_t pop_selected_stake_token_value(std::vector<size_t> &unused_indices, const std::vector<size_t>& selected_transfers, const cryptonote::tx_out_type out_type, const uint64_t cash_amount, const uint64_t token_amount, const uint64_t staked_token_height) const;


void set_tx_note(const crypto::hash &txid, const std::string &note);
std::string get_tx_note(const crypto::hash &txid) const;
Expand Down

0 comments on commit 6314563

Please sign in to comment.