From 2506d51d60eb31fefc36ca012694ef2454fc9277 Mon Sep 17 00:00:00 2001 From: Kenshi Takayama Date: Wed, 14 Dec 2016 20:44:09 +0900 Subject: [PATCH] wallet cli: donate command --- src/simplewallet/simplewallet.cpp | 40 +++++++++++++++++++++++++++++++ src/simplewallet/simplewallet.h | 1 + 2 files changed, 41 insertions(+) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 85bdee16f..b46447975 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -663,6 +663,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("locked_transfer", boost::bind(&simple_wallet::locked_transfer, this, _1), tr("locked_transfer [] (Number of blocks to lock the transaction for, max 1000000) []")); m_cmd_binder.set_handler("sweep_unmixable", boost::bind(&simple_wallet::sweep_unmixable, this, _1), tr("Send all unmixable outputs to yourself with mixin 0")); m_cmd_binder.set_handler("sweep_all", boost::bind(&simple_wallet::sweep_all, this, _1), tr("sweep_all [mixin] address [payment_id] - Send all unlocked balance an address")); + m_cmd_binder.set_handler("donate", boost::bind(&simple_wallet::donate, this, _1), tr("donate [] [payment_id] - Donate to the development team (donate.getmonero.org)")); m_cmd_binder.set_handler("sign_transfer", boost::bind(&simple_wallet::sign_transfer, this, _1), tr("Sign a transaction from a file")); m_cmd_binder.set_handler("submit_transfer", boost::bind(&simple_wallet::submit_transfer, this, _1), tr("Submit a signed transaction from a file")); m_cmd_binder.set_handler("set_log", boost::bind(&simple_wallet::set_log, this, _1), tr("set_log - Change current log detail level, <0-4>")); @@ -2826,6 +2827,45 @@ bool simple_wallet::sweep_all(const std::vector &args_) return true; } //---------------------------------------------------------------------------------------------------- +bool simple_wallet::donate(const std::vector &args_) +{ + std::vector local_args = args_; + if(local_args.empty() || local_args.size() > 3) + { + fail_msg_writer() << tr("wrong number of arguments"); + return true; + } + std::string mixin_str; + std::string address_str = "donate.getmonero.org"; + std::string amount_str; + std::string payment_id_str; + // check payment id + crypto::hash payment_id; + crypto::hash8 payment_id8; + if (tools::wallet2::parse_long_payment_id (local_args.back(), payment_id ) || + tools::wallet2::parse_short_payment_id(local_args.back(), payment_id8)) + { + payment_id_str = local_args.back(); + local_args.pop_back(); + } + // check mixin + if (local_args.size() > 1) + { + mixin_str = local_args[0]; + local_args.erase(local_args.begin()); + } + amount_str = local_args[0]; + // refill args as necessary + local_args.clear(); + if (!mixin_str.empty()) + local_args.push_back(mixin_str); + local_args.push_back(address_str); + local_args.push_back(amount_str); + if (!payment_id_str.empty()) + local_args.push_back(payment_id_str); + transfer_new(local_args); +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::accept_loaded_tx(const std::function get_num_txes, const std::function &get_tx, const std::string &extra_message) { // gather info to ask the user diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 0d83f429b..420597699 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -124,6 +124,7 @@ namespace cryptonote bool locked_transfer(const std::vector &args); bool sweep_all(const std::vector &args); bool sweep_unmixable(const std::vector &args); + bool donate(const std::vector &args); bool sign_transfer(const std::vector &args); bool submit_transfer(const std::vector &args); std::vector> split_amounts(