Skip to content

Commit

Permalink
Transaction history and 'reset' command for simplewallet
Browse files Browse the repository at this point in the history
  • Loading branch information
jezal committed Aug 26, 2014
1 parent c3b1a00 commit 9df3a81
Show file tree
Hide file tree
Showing 17 changed files with 373 additions and 95 deletions.
6 changes: 6 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Release notes 1.0.2

- Transaction history for simplewallet
- Reset command for simplewallet
- Various simplewallet improvements

Release notes 1.0.1

- Fix transfers in simplewallet
Expand Down
6 changes: 4 additions & 2 deletions src/cryptonote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const uint64_t CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS = DIFFICULTY_TARGET
const uint64_t CRYPTONOTE_MEMPOOL_TX_LIVETIME = 60 * 60 * 24; //seconds, one day
const uint64_t CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME = 60 * 60 * 24 * 7; //seconds, one week

const uint64_t UPGRADE_HEIGHT = 546602;
const unsigned UPGRADE_VOTING_THRESHOLD = 90; // percent
const size_t UPGRADE_VOTING_WINDOW = EXPECTED_NUMBER_OF_BLOCKS_PER_DAY; // blocks
const size_t UPGRADE_WINDOW = EXPECTED_NUMBER_OF_BLOCKS_PER_DAY; // blocks
Expand Down Expand Up @@ -104,7 +105,7 @@ const uint32_t P2P_DEFAULT_CONNECTION_TIMEOUT = 5000; //
const uint32_t P2P_DEFAULT_PING_CONNECTION_TIMEOUT = 2000; // 2 seconds
const uint64_t P2P_DEFAULT_INVOKE_TIMEOUT = 60 * 2 * 1000; // 2 minutes
const size_t P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT = 5000; // 5 seconds
const char P2P_STAT_TRUSTED_PUB_KEY[] = "8f80f9a5a434a9f1510d13336228debfee9c918ce505efe225d8c94d045fa115";
const char P2P_STAT_TRUSTED_PUB_KEY[] = "93467628927eaa0b13a4e52e61864a75aa475e67f6b5748eb3fc1d2fe468aed4";
const size_t P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT = 70;

const unsigned THREAD_STACK_SIZE = 5 * 1024 * 1024;
Expand Down Expand Up @@ -143,7 +144,8 @@ const CheckpointData CHECKPOINTS[] = {
{480200, "363544ac9920c778b815c2fdbcbca70a0d79b21f662913a42da9b49e859f0e5b"},
{484500, "5cdf2101a0a62a0ab2a1ca0c15a6212b21f6dbdc42a0b7c0bcf65ca40b7a14fb"},
{506000, "3d54c1132f503d98d3f0d78bb46a4503c1a19447cb348361a2232e241cb45a3c"},
{544000, "f69dc61b6a63217f32fa64d5d0f9bd920873f57dfd79ebe1d7d6fb1345b56fe0"}
{544000, "f69dc61b6a63217f32fa64d5d0f9bd920873f57dfd79ebe1d7d6fb1345b56fe0"},
{553300, "f7a5076b887ce5f4bb95b2729c0edb6f077a463f04f1bffe7f5cb0b16bb8aa5f"}
};
} // cryptonote

Expand Down
3 changes: 2 additions & 1 deletion src/cryptonote_core/Currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace cryptonote {
CHECK_AND_ASSERT_MES(r, false, "Failed to get genesis block hash");

if (isTestnet()) {
m_upgradeHeight = 0;
m_blocksFileName = "testnet_" + m_blocksFileName;
m_blocksCacheFileName = "testnet_" + m_blocksCacheFileName;
m_blockIndexesFileName = "testnet_" + m_blockIndexesFileName;
Expand Down Expand Up @@ -380,7 +381,7 @@ namespace cryptonote {
mempoolTxLiveTime(parameters::CRYPTONOTE_MEMPOOL_TX_LIVETIME);
mempoolTxFromAltBlockLiveTime(parameters::CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME);

upgradeHeight(UpgradeDetectorBase::UNDEF_HEIGHT);
upgradeHeight(parameters::UPGRADE_HEIGHT);
upgradeVotingThreshold(parameters::UPGRADE_VOTING_THRESHOLD);
upgradeVotingWindow(parameters::UPGRADE_VOTING_WINDOW);
upgradeWindow(parameters::UPGRADE_WINDOW);
Expand Down
25 changes: 20 additions & 5 deletions src/cryptonote_core/blockchain_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ namespace cryptonote
if (version < CURRENT_BLOCKCACHE_STORAGE_ARCHIVE_VER)
return;

std::string operation;
if (Archive::is_loading::value) {

operation = "- loading ";
crypto::hash blockHash;
ar & blockHash;

Expand All @@ -241,13 +242,23 @@ namespace cryptonote
}

} else {
operation = "- saving ";
ar & m_lastBlockHash;
}

LOG_PRINT_L0(operation << "block index...");
ar & m_bs.m_blockIndex;

LOG_PRINT_L0(operation << "transaction map...");
ar & m_bs.m_transactionMap;

LOG_PRINT_L0(operation << "spend keys...");
ar & m_bs.m_spent_keys;

LOG_PRINT_L0(operation << "outputs...");
ar & m_bs.m_outputs;

LOG_PRINT_L0(operation << "multi-signature outputs...");
ar & m_bs.m_multisignatureOutputs;

m_loaded = true;
Expand Down Expand Up @@ -377,6 +388,9 @@ bool blockchain_storage::init(const std::string& config_folder, bool load_existi
m_outputs.clear();
m_multisignatureOutputs.clear();
for (uint32_t b = 0; b < m_blocks.size(); ++b) {
if (b % 1000 == 0) {
std::cout << "Height " << b << " of " << m_blocks.size() << '\r';
}
const BlockEntry& block = m_blocks[b];
crypto::hash blockHash = get_block_hash(block.bl);
m_blockIndex.push(blockHash);
Expand Down Expand Up @@ -435,6 +449,7 @@ bool blockchain_storage::init(const std::string& config_folder, bool load_existi
bool blockchain_storage::storeCache() {
CRITICAL_REGION_LOCAL(m_blockchain_lock);

LOG_PRINT_L0("Saving blockchain...");
BlockCacheSerializer ser(*this, get_tail_id());
if (!tools::serialize_obj_to_file(ser, appendPath(m_config_folder, m_currency.blocksCacheFileName()))) {
LOG_ERROR("Failed to save blockchain cache");
Expand Down Expand Up @@ -900,9 +915,9 @@ bool blockchain_storage::handle_alternative_block(const Block& b, const crypto::
}

if (!m_checkpoints.is_alternative_block_allowed(get_current_blockchain_height(), block_height)) {
LOG_PRINT_RED_L0("Block with id: " << id
<< ENDL << " can't be accepted for alternative chain, block height: " << block_height
<< ENDL << " blockchain height: " << get_current_blockchain_height());
LOG_PRINT_L2("Block with id: " << id << std::endl <<
" can't be accepted for alternative chain, block height: " << block_height << std::endl <<
" blockchain height: " << get_current_blockchain_height());
bvc.m_verifivation_failed = true;
return false;
}
Expand Down Expand Up @@ -1525,7 +1540,7 @@ bool blockchain_storage::checkBlockVersion(const Block& b, const crypto::hash& b
uint64_t height = get_block_height(b);
const uint8_t expectedBlockVersion = get_block_major_version_for_height(height);
if (b.majorVersion != expectedBlockVersion) {
LOG_PRINT_L0("Block " << blockHash << " has wrong major version: " << static_cast<int>(b.majorVersion) <<
LOG_PRINT_L2("Block " << blockHash << " has wrong major version: " << static_cast<int>(b.majorVersion) <<
", at height " << height << " expected version is " << static_cast<int>(expectedBlockVersion));
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cryptonote_core/cryptonote_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ namespace cryptonote

if(!keeped_by_block && get_object_blobsize(tx) >= m_blockchain_storage.get_current_comulative_blocksize_limit() - m_currency.minerTxBlobReservedSize())
{
LOG_PRINT_RED_L0("tx have to big size " << get_object_blobsize(tx) << ", expected not bigger than " <<
LOG_PRINT_RED_L0("transaction is too big " << get_object_blobsize(tx) << ", maximum allowed size is " <<
(m_blockchain_storage.get_current_comulative_blocksize_limit() - m_currency.minerTxBlobReservedSize()));
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions src/cryptonote_protocol/cryptonote_protocol_handler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ namespace cryptonote

int64_t diff = static_cast<int64_t>(hshd.current_height) - static_cast<int64_t>(m_core.get_current_blockchain_height());
LOG_PRINT_CCONTEXT_YELLOW("Sync data returned unknown top block: " << m_core.get_current_blockchain_height() << " -> " << hshd.current_height
<< " [" << std::abs(diff) << " blocks (" << diff / (24 * 60 * 60 / m_core.currency().difficultyTarget()) << " days) "
<< (0 <= diff ? std::string("behind") : std::string("ahead"))
<< "] " << ENDL << "SYNCHRONIZATION started", (is_inital ? LOG_LEVEL_0:LOG_LEVEL_1));
<< " [" << std::abs(diff) << " blocks (" << std::abs(diff) / (24 * 60 * 60 / m_core.currency().difficultyTarget()) << " days) "
<< (diff >= 0 ? std::string("behind") : std::string("ahead")) << "] " << std::endl <<
"SYNCHRONIZATION started", (diff >= 0 ? (is_inital ? LOG_LEVEL_0 : LOG_LEVEL_1) : LOG_LEVEL_2));
LOG_PRINT_L1("Remote top block height: " << hshd.current_height << ", id: " << hshd.top_id);
context.m_state = cryptonote_connection_context::state_synchronizing;
context.m_remote_blockchain_height = hshd.current_height;
Expand Down Expand Up @@ -173,7 +173,7 @@ namespace cryptonote
block_verification_context bvc = boost::value_initialized<block_verification_context>();
m_core.handle_incoming_block_blob(arg.b.block, bvc, true, false);
if (bvc.m_verifivation_failed) {
LOG_PRINT_CCONTEXT_L0("Block verification failed, dropping connection");
LOG_PRINT_CCONTEXT_L1("Block verification failed, dropping connection");
m_p2p->drop_connection(context);
return 1;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ namespace cryptonote
m_core.handle_incoming_block_blob(block_entry.block, bvc, false, false);

if (bvc.m_verifivation_failed) {
LOG_PRINT_CCONTEXT_L0("Block verification failed, dropping connection");
LOG_PRINT_CCONTEXT_L1("Block verification failed, dropping connection");
m_p2p->drop_connection(context);
return 1;
} else if (bvc.m_marked_as_orphaned) {
Expand Down
59 changes: 52 additions & 7 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace
}

if (!r) {
fail_msg_writer() << "payment id has invalid format: \"" << value << "\", expected 64-character string";
fail_msg_writer() << "payment ID has invalid format: \"" << value << "\", expected 64-character string";
return false;
}
} else if (arg == "-f") {
Expand All @@ -249,7 +249,13 @@ namespace
cryptonote::tx_destination_entry de;

if (!m_currency.parseAccountAddressString(arg, de.addr)) {
fail_msg_writer() << "wrong address: " << arg;
crypto::hash paymentId;
if (tools::wallet2::parse_payment_id(arg, paymentId)) {
fail_msg_writer() << "Invalid payment ID usage. Please, use -p <payment_id>. See help for details.";
} else {
fail_msg_writer() << "Wrong address: " << arg;
}

return false;
}

Expand Down Expand Up @@ -307,6 +313,7 @@ simple_wallet::simple_wallet(const cryptonote::Currency& currency)
m_cmd_binder.set_handler("refresh", boost::bind(&simple_wallet::refresh, this, _1), "Resynchronize transactions and balance");
m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, _1), "Show current wallet balance");
m_cmd_binder.set_handler("incoming_transfers", boost::bind(&simple_wallet::show_incoming_transfers, this, _1), "incoming_transfers [available|unavailable] - Show incoming transfers - all of them or filter them by availability");
m_cmd_binder.set_handler("list_transfers", boost::bind(&simple_wallet::listTransfers, this, _1), "Show all known transfers");
m_cmd_binder.set_handler("payments", boost::bind(&simple_wallet::show_payments, this, _1), "payments <payment_id_1> [<payment_id_2> ... <payment_id_N>] - Show payments <payment_id_1>, ... <payment_id_N>");
m_cmd_binder.set_handler("bc_height", boost::bind(&simple_wallet::show_blockchain_height, this, _1), "Show blockchain height");
m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::transfer, this, _1),
Expand All @@ -316,6 +323,7 @@ simple_wallet::simple_wallet(const cryptonote::Currency& currency)
m_cmd_binder.set_handler("set_log", boost::bind(&simple_wallet::set_log, this, _1), "set_log <level> - Change current log detalization level, <level> is a number 0-4");
m_cmd_binder.set_handler("address", boost::bind(&simple_wallet::print_address, this, _1), "Show current wallet public address");
m_cmd_binder.set_handler("save", boost::bind(&simple_wallet::save, this, _1), "Save wallet synchronized data");
m_cmd_binder.set_handler("reset", boost::bind(&simple_wallet::reset, this, _1), "Discard cache data and start synchronizing from the start");
m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), "Show this help");
}
//----------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -560,7 +568,14 @@ bool simple_wallet::save(const std::vector<std::string> &args)

return true;
}
//----------------------------------------------------------------------------------------------------

bool simple_wallet::reset(const std::vector<std::string> &args) {
m_wallet->reset();
success_msg_writer(true) << "Reset is complete successfully";
refresh();
return true;
}

bool simple_wallet::start_mining(const std::vector<std::string>& args)
{
if (!try_connect_to_daemon())
Expand Down Expand Up @@ -652,7 +667,7 @@ void simple_wallet::on_skip_transaction(uint64_t height, const cryptonote::Trans
m_refresh_progress_reporter.update(height, true);
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::refresh(const std::vector<std::string>& args)
bool simple_wallet::refresh(const std::vector<std::string>& args/* = std::vector<std::string>()*/)
{
if (!try_connect_to_daemon())
return true;
Expand Down Expand Up @@ -776,12 +791,35 @@ bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args

return true;
}
//----------------------------------------------------------------------------------------------------

bool simple_wallet::listTransfers(const std::vector<std::string>& args) {
const std::vector<tools::wallet2::Transfer>& transfers = m_wallet->getTransfers();
for (const tools::wallet2::Transfer& transfer : transfers) {
std::string address = "UNKNOWN";
if (transfer.hasAddress) {
address = getAccountAddressAsStr(m_currency.publicAddressBase58Prefix(), transfer.address);
}

message_writer(transfer.output ? epee::log_space::console_color_magenta : epee::log_space::console_color_green, false)
<< transfer.time
<< ", " << (transfer.output ? "OUTPUT" : "INPUT")
<< ", " << transfer.transactionHash
<< ", " << m_currency.formatAmount(transfer.amount)
<< ", " << m_currency.formatAmount(transfer.fee)
<< ", " << transfer.paymentId
<< ", " << address
<< ", " << transfer.blockIndex
<< ", " << transfer.unlockTime;
}

return true;
}

bool simple_wallet::show_payments(const std::vector<std::string> &args)
{
if(args.empty())
{
fail_msg_writer() << "expected at least one payment_id";
fail_msg_writer() << "expected at least one payment ID";
return true;
}

Expand Down Expand Up @@ -819,7 +857,7 @@ bool simple_wallet::show_payments(const std::vector<std::string> &args)
}
else
{
fail_msg_writer() << "payment id has invalid format: \"" << arg << "\", expected 64-character string";
fail_msg_writer() << "payment ID has invalid format: \"" << arg << "\", expected 64-character string";
}
}

Expand Down Expand Up @@ -864,6 +902,13 @@ bool simple_wallet::transfer(const std::vector<std::string> &args)
cryptonote::Transaction tx;
m_wallet->transfer(cmd.dsts, cmd.fake_outs_count, 0, cmd.fee, cmd.extra, tx);
success_msg_writer(true) << "Money successfully sent, transaction " << get_transaction_hash(tx);

try {
m_wallet->store();
} catch (const std::exception& e) {
fail_msg_writer() << e.what();
return false;
}
}
catch (const tools::error::daemon_busy&)
{
Expand Down
4 changes: 3 additions & 1 deletion src/simplewallet/simplewallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ namespace cryptonote
bool help(const std::vector<std::string> &args = std::vector<std::string>());
bool start_mining(const std::vector<std::string> &args);
bool stop_mining(const std::vector<std::string> &args);
bool refresh(const std::vector<std::string> &args);
bool refresh(const std::vector<std::string> &args = std::vector<std::string>());
bool show_balance(const std::vector<std::string> &args = std::vector<std::string>());
bool show_incoming_transfers(const std::vector<std::string> &args);
bool show_payments(const std::vector<std::string> &args);
bool show_blockchain_height(const std::vector<std::string> &args);
bool listTransfers(const std::vector<std::string> &args);
bool transfer(const std::vector<std::string> &args);
bool print_address(const std::vector<std::string> &args = std::vector<std::string>());
bool save(const std::vector<std::string> &args);
bool reset(const std::vector<std::string> &args);
bool set_log(const std::vector<std::string> &args);

uint64_t get_daemon_blockchain_height(std::string& err);
Expand Down
4 changes: 2 additions & 2 deletions src/version.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define BUILD_COMMIT_ID "@VERSION@"
#define PROJECT_VERSION "1.0.1"
#define PROJECT_VERSION_BUILD_NO "316"
#define PROJECT_VERSION "1.0.2"
#define PROJECT_VERSION_BUILD_NO "336"
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO "(" BUILD_COMMIT_ID ")"
2 changes: 1 addition & 1 deletion src/wallet/WalletTransactionSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ WalletTransactionSender::WalletTransactionSender(const cryptonote::Currency& cur
m_unconfirmedTransactions(unconfirmedTransactions),
m_isInitialized(false),
m_isStoping(false) {
m_upperTransactionSizeLimit = (cryptonote::parameters::CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 * 125) / 100 - m_currency.minerTxBlobReservedSize();
m_upperTransactionSizeLimit = m_currency.blockGrantedFullRewardZone() * 125 / 100 - m_currency.minerTxBlobReservedSize();
}

void WalletTransactionSender::init(cryptonote::account_keys keys) {
Expand Down
Loading

0 comments on commit 9df3a81

Please sign in to comment.