//-------------------------------------------------------------------------------- bool DaemonCommandsHandler::print_block_by_hash(const std::string& arg) { Crypto::Hash block_hash; if (!parse_hash256(arg, block_hash)) { return false; } std::list<Crypto::Hash> block_ids; block_ids.push_back(block_hash); std::list<CryptoNote::Block> blocks; std::list<Crypto::Hash> missed_ids; m_core.get_blocks(block_ids, blocks, missed_ids); if (1 == blocks.size()) { print_as_json(blocks.front()); } else { std::cout << "block wasn't found: " << arg << std::endl; return false; } return true; }
//-------------------------------------------------------------------------------- bool DaemonCommandsHandler::print_stat(const std::vector<std::string>& args) { uint32_t height = 0; uint32_t maxHeight = m_core.get_current_blockchain_height() - 1; if (args.empty()) { height = maxHeight; } else { try { height = boost::lexical_cast<uint32_t>(args.front()); } catch (boost::bad_lexical_cast&) { Crypto::Hash block_hash; if (!parse_hash256(args.front(), block_hash) || !m_core.getBlockHeight(block_hash, height)) { return false; } } if (height > maxHeight) { std::cout << "printing for last available block: " << maxHeight << std::endl; height = maxHeight; } } uint64_t totalCoinsInNetwork = m_core.coinsEmittedAtHeight(height); uint64_t totalCoinsOnDeposits = m_core.depositAmountAtHeight(height); uint64_t amountOfActiveCoins = totalCoinsInNetwork - totalCoinsOnDeposits; const auto& currency = m_core.currency(); std::cout << "Block height: " << height << std::endl; std::cout << "Block difficulty: " << m_core.difficultyAtHeight(height) << std::endl; std::cout << "Total coins in network: " << currency.formatAmount(totalCoinsInNetwork) << std::endl; std::cout << "Total coins on deposits: " << currency.formatAmount(totalCoinsOnDeposits) << " (" << currency.formatAmount(calculatePercent(currency, totalCoinsOnDeposits, totalCoinsInNetwork)) << "%)" << std::endl; std::cout << "Amount of active coins: " << currency.formatAmount(amountOfActiveCoins) << " (" << currency.formatAmount(calculatePercent(currency, amountOfActiveCoins, totalCoinsInNetwork)) << "%)" << std::endl; std::cout << "Total interest paid: " << currency.formatAmount(m_core.depositInterestAtHeight(height)) << std::endl; return true; }
bool parse_str_secret_key(const string& key_str, T& secret_key) { // hash and keys have same structure, so to parse string of // a key, e.g., a view key, we can first parse it into the hash // object using parse_hash256 function, and then copy the reslting // hash data into secret key. crypto::hash hash_; if(!parse_hash256(key_str, hash_)) { cerr << "Cant parse a key (e.g. viewkey): " << key_str << endl; return false; } // crypto::hash and crypto::secret_key have basicly same // structure. They both keep they key/hash as c-style char array // of fixed size. Thus we can just copy data from hash // to key copy(begin(hash_.data), end(hash_.data), secret_key.data); return true; }
void txProof(CryptoNote::WalletGreen &wallet) { std::string txHashStr; Crypto::Hash txid; while (true) { std::cout << InformationMsg("Enter transaction hash: "); std::getline(std::cin, txHashStr); boost::algorithm::trim(txHashStr); if (!parse_hash256(txHashStr, txid)) { std::cout << WarningMsg("Failed to parse txid") << std::endl; return; } else { break; } if (std::cin.fail() || std::cin.eof()) { std::cin.clear(); break; } } Crypto::SecretKey txSecretKey = wallet.getTransactionSecretKey(txid); if (txSecretKey == CryptoNote::NULL_SECRET_KEY) { std::cout << InformationMsg("Transaction ") << InformationMsg(txHashStr) << InformationMsg(" secret key is not available.") << std::endl << InformationMsg("If you have it elsewhere, ") << InformationMsg("enter it here to continue: ") << std::endl; Crypto::Hash tx_key_hash; while (true) { std::string keyStr; std::getline(std::cin, keyStr); boost::algorithm::trim(keyStr); size_t size; if (!Common::fromHex(keyStr, &tx_key_hash, sizeof(tx_key_hash), size) || size != sizeof(tx_key_hash)) { std::cout << WarningMsg("Failed to parse tx secret key ") << WarningMsg(keyStr) << std::endl; return; } else { txSecretKey = *(struct Crypto::SecretKey *) &tx_key_hash; break; } if (std::cin.fail() || std::cin.eof()) { std::cin.clear(); break; } } } CryptoNote::AccountPublicAddress destAddress; while (true) { std::cout << InformationMsg("Enter destination address: "); std::string addrStr; uint64_t prefix; std::getline(std::cin, addrStr); boost::algorithm::trim(addrStr); if (!CryptoNote::parseAccountAddressString(prefix, destAddress, addrStr)) { std::cout << WarningMsg("Failed to parse address") << std::endl; } else { break; } if (std::cin.fail() || std::cin.eof()) { std::cin.clear(); break; } } try { std::string sig; if (wallet.getTransactionProof(txid, destAddress, txSecretKey, sig)) { std::cout << SuccessMsg("Transaction proof: ") << std::endl << SuccessMsg(sig) << std::endl; } else { std::cout << WarningMsg("Failed to get transaction proof") << std::endl; } } catch (std::system_error& x) { std::cout << WarningMsg("Error while getting transaction proof: ") << WarningMsg(x.what()) << std::endl; } catch (std::exception& x) { std::cout << WarningMsg("Error while getting transaction proof: ") << WarningMsg(x.what()) << std::endl; } }