1
0
Fork 0
forked from lthn/blockchain

Merge branch 'master' into frontend

This commit is contained in:
wildkif 2019-05-07 10:30:17 +03:00
commit a2e31ff84d
9 changed files with 116 additions and 17 deletions

View file

@ -304,7 +304,7 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro
<< "last block: " << m_db_blocks.size() - 1 << ", " << misc_utils::get_time_interval_string(timestamp_diff) << " time ago" << ENDL
<< "current pos difficulty: " << get_next_diff_conditional(true) << ENDL
<< "current pow difficulty: " << get_next_diff_conditional(false) << ENDL
<< "total tansactions: " << m_db_transactions.size(),
<< "total transactions: " << m_db_transactions.size(),
LOG_LEVEL_0);

View file

@ -4512,7 +4512,7 @@ var MainComponent = /** @class */ (function () {
});
};
MainComponent.prototype.openInBrowser = function () {
this.backend.openUrlInBrowser('docs.zano.org/v1.0/docs/how-to-create-wallet');
this.backend.openUrlInBrowser('docs.zano.org/docs/getting-started-1#section-create-new-wallet');
};
MainComponent.prototype.back = function () {
this.location.back();

File diff suppressed because one or more lines are too long

View file

@ -37,7 +37,7 @@ export class MainComponent implements OnInit {
}
openInBrowser() {
this.backend.openUrlInBrowser('docs.zano.org/v1.0/docs/how-to-create-wallet');
this.backend.openUrlInBrowser('docs.zano.org/docs/getting-started-1#section-create-new-wallet');
}
back() {

View file

@ -2102,9 +2102,9 @@ uint64_t wallet2::balance(uint64_t& unloked) const
return balance(unloked, fake, fake, fake);
}
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::balance(uint64_t& unloked, uint64_t& awaiting_in, uint64_t& awaiting_out, uint64_t& mined) const
uint64_t wallet2::balance(uint64_t& unlocked, uint64_t& awaiting_in, uint64_t& awaiting_out, uint64_t& mined) const
{
unloked = 0;
unlocked = 0;
uint64_t balance_total = 0;
awaiting_in = 0;
awaiting_out = 0;
@ -2124,7 +2124,7 @@ uint64_t wallet2::balance(uint64_t& unloked, uint64_t& awaiting_in, uint64_t& aw
{
balance_total += td.amount();
if (is_transfer_unlocked(td))
unloked += td.amount();
unlocked += td.amount();
if (td.m_flags & WALLET_TRANSFER_DETAIL_FLAG_MINED_TRANSFER)
mined += td.amount();
// bool pos_coinbase = false;
@ -4082,16 +4082,24 @@ void wallet2::transfer(const std::vector<currency::tx_destination_entry>& dsts,
return;
}
TIME_MEASURE_START(finalize_transaction_time);
crypto::secret_key sk = AUTO_VAL_INIT(sk);
finalize_transaction(ftp, tx, sk, send_to_network);
TIME_MEASURE_FINISH(finalize_transaction_time);
// unlock transfers at the very end
TIME_MEASURE_START(mark_transfers_as_spent_time);
mark_transfers_as_spent(ftp.selected_transfers, std::string("money transfer, tx: ") + epee::string_tools::pod_to_hex(get_transaction_hash(tx)));
TIME_MEASURE_FINISH(mark_transfers_as_spent_time);
TIME_MEASURE_START(finalize_transaction_time);
try
{
crypto::secret_key sk = AUTO_VAL_INIT(sk);
finalize_transaction(ftp, tx, sk, send_to_network);
}
catch (...)
{
clear_transfers_from_flag(ftp.selected_transfers, WALLET_TRANSFER_DETAIL_FLAG_SPENT, std::string("exception on money transfer, tx: ") + epee::string_tools::pod_to_hex(get_transaction_hash(tx)));
throw;
}
TIME_MEASURE_FINISH(finalize_transaction_time);
WLT_LOG_GREEN("[wallet::transfer]"
<< " precalculation_time: " << print_fixed_decimal_point(precalculation_time, 3)
<< ", prepare_transaction_time: " << print_fixed_decimal_point(prepare_transaction_time, 3)

View file

@ -368,7 +368,7 @@ namespace tools
uint64_t amount() const { return m_ptx_wallet_info->m_tx.vout[m_internal_output_index].amount; }
bool is_spent() const { return m_flags & WALLET_TRANSFER_DETAIL_FLAG_SPENT; }
bool is_spendable() const { return (m_flags & (~WALLET_TRANSFER_DETAIL_FLAG_MINED_TRANSFER)) == 0; } // spenable = has no flags or mined flag only
bool is_spendable() const { return (m_flags & (WALLET_TRANSFER_DETAIL_FLAG_SPENT | WALLET_TRANSFER_DETAIL_FLAG_BLOCKED | WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION | WALLET_TRANSFER_DETAIL_FLAG_COLD_SIG_RESERVATION)) == 0; }
bool is_reserved_for_escrow() const { return ( (m_flags & WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION) != 0 ); }
BEGIN_KV_SERIALIZE_MAP()

View file

@ -809,6 +809,7 @@ int main(int argc, char* argv[])
GENERATE_AND_PLAY(mined_balance_wallet_test);
GENERATE_AND_PLAY(wallet_outputs_with_same_key_image);
GENERATE_AND_PLAY(wallet_unconfirmed_tx_expiration);
GENERATE_AND_PLAY(wallet_unconfimed_tx_balance);
GENERATE_AND_PLAY(wallet_rpc_integrated_address);
GENERATE_AND_PLAY(wallet_rpc_integrated_address_transfer);

View file

@ -24,11 +24,11 @@ const currency::account_base null_account = AUTO_VAL_INIT(null_account);
struct wlt_lambda_on_transfer2_wrapper : public tools::i_wallet2_callback
{
typedef std::function<bool(const tools::wallet_rpc::wallet_transfer_info&)> Func;
typedef std::function<bool(const tools::wallet_rpc::wallet_transfer_info&, uint64_t, uint64_t, uint64_t)> Func;
wlt_lambda_on_transfer2_wrapper(Func callback) : m_result(false), m_callback(callback) {}
virtual void on_transfer2(const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) override
{
m_result = m_callback(wti);
m_result = m_callback(wti, balance, unlocked_balance, total_mined);
}
bool m_result;
Func m_callback;
@ -1777,7 +1777,7 @@ bool gen_wallet_alias_via_special_wallet_funcs::c1(currency::core& c, size_t ev_
uint64_t biggest_alias_reward = get_alias_coast_from_fee("a", TESTS_DEFAULT_FEE);
std::shared_ptr<wlt_lambda_on_transfer2_wrapper> l(new wlt_lambda_on_transfer2_wrapper(
[biggest_alias_reward](const tools::wallet_rpc::wallet_transfer_info& wti) -> bool {
[biggest_alias_reward](const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) -> bool {
return std::count(wti.recipients_aliases.begin(), wti.recipients_aliases.end(), "minerminer") == 1 &&
wti.amount == biggest_alias_reward;
}
@ -3214,3 +3214,86 @@ bool wallet_chain_switch_with_spending_the_same_ki::c1(currency::core& c, size_t
return true;
}
//------------------------------------------------------------------------------
wallet_unconfimed_tx_balance::wallet_unconfimed_tx_balance()
{
REGISTER_CALLBACK_METHOD(wallet_unconfimed_tx_balance, c1);
}
bool wallet_unconfimed_tx_balance::generate(std::vector<test_event_entry>& events) const
{
// Test outline:
// 1. Miner sends 100 coins to Alice (50 + 50)
// 2. Alice sends 30 back to Miner (tx is unconfirmed)
// 3. Make sure Alice's wallet has correct balance, when it is checked from wallet's callback
// 4. Few blocks are mined so the tx is get confirmed
// 5. Make sure Alice's balance has changed correctly
m_accounts.resize(TOTAL_ACCS_COUNT);
account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate();
account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate();
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time());
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
MAKE_TX(events, tx_0, miner_acc, alice_acc, MK_TEST_COINS(50), blk_0r);
MAKE_TX(events, tx_1, miner_acc, alice_acc, MK_TEST_COINS(50), blk_0r);
MAKE_NEXT_BLOCK_TX_LIST(events, blk_1, blk_0r, miner_acc, std::list<transaction>({ tx_0, tx_1 }));
REWIND_BLOCKS_N(events, blk_1r, blk_1, miner_acc, WALLET_DEFAULT_TX_SPENDABLE_AGE);
DO_CALLBACK(events, "c1");
return true;
}
bool wallet_unconfimed_tx_balance::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
bool r = false;
std::shared_ptr<tools::wallet2> alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX);
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, MK_TEST_COINS(100), false, UINT64_MAX, MK_TEST_COINS(100)), false, "");
bool callback_is_ok = false;
// this callback will ba called from within wallet2::transfer() below
std::shared_ptr<wlt_lambda_on_transfer2_wrapper> l(new wlt_lambda_on_transfer2_wrapper(
[&callback_is_ok](const tools::wallet_rpc::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) -> bool
{
CHECK_AND_ASSERT_MES(balance == MK_TEST_COINS(70), false, "invalid balance: " << print_money_brief(balance));
CHECK_AND_ASSERT_MES(unlocked_balance == MK_TEST_COINS(50), false, "invalid unlocked_balance: " << print_money_brief(unlocked_balance));
CHECK_AND_ASSERT_MES(total_mined == 0, false, "invalid total_mined: " << print_money_brief(total_mined));
callback_is_ok = true;
return true;
}
));
alice_wlt->callback(l);
uint64_t fee = TESTS_DEFAULT_FEE * 3;
std::vector<tx_destination_entry> destinations{ tx_destination_entry(MK_TEST_COINS(30) - fee, m_accounts[MINER_ACC_IDX].get_public_address()) };
try
{
alice_wlt->transfer(destinations, 0, 0, fee, empty_extra, empty_attachment);
}
catch (std::exception &e)
{
CHECK_AND_ASSERT_MES(false, false, "alice_wlt->transfer() caused an exception: " << e.what());
}
CHECK_AND_NO_ASSERT_MES(callback_is_ok, false, "callback failed");
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Tx pool has incorrect number of txs: " << c.get_pool_transactions_count());
// 50 coins should be locked and 50 - unlocked
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, MK_TEST_COINS(70), false, UINT64_MAX, MK_TEST_COINS(50), 0, 0, MK_TEST_COINS(30) - fee), false, "");
// mine WALLET_DEFAULT_TX_SPENDABLE_AGE blocks so the tx get confirmed and coins get unlocked
CHECK_AND_ASSERT_MES(mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE), false, "");
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Tx pool has incorrect number of txs: " << c.get_pool_transactions_count());
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, MK_TEST_COINS(70), false, UINT64_MAX, MK_TEST_COINS(70), 0, 0, 0), false, "");
return true;
}

View file

@ -244,3 +244,10 @@ struct wallet_chain_switch_with_spending_the_same_ki : public wallet_test
bool generate(std::vector<test_event_entry>& events) const;
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
};
struct wallet_unconfimed_tx_balance : public wallet_test
{
wallet_unconfimed_tx_balance();
bool generate(std::vector<test_event_entry>& events) const;
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
};