// // monero_send_routine.hpp // Copyright (c) 2014-2019, MyMonero.com // // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, are // permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this list of // conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, this list // of conditions and the following disclaimer in the documentation and/or other // materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its contributors may be // used to endorse or promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // #ifndef monero_send_routine_hpp #define monero_send_routine_hpp // #include #include // #include "string_tools.h" #include "crypto.h" #include "cryptonote_basic.h" #include "cryptonote_format_utils.h" // using namespace tools; #include "tools__ret_vals.hpp" // #include "monero_transfer_utils.hpp" // namespace monero_send_routine { using namespace std; using namespace boost; using namespace cryptonote; using namespace monero_transfer_utils; using namespace crypto; // // Abstracted Send routine // - Accessory types - Callbacks - Data fetch hooks typedef std::function api_fetch_cb_fn; // struct LightwalletAPI_Req_GetUnspentOuts { // strings are NOT references, so they get copied, allowing scope of struct init not to be an issue const string address; const string view_key; const string amount; // "0" uint64_string size_t mixin; bool use_dust; // true; send-funds is now coded to filter unmixable and below threshold dust properly when sweeping and not sweeping const string dust_threshold; // uint64_string; String(MoneroConstants.dustThreshold, radix: 10) }; LightwalletAPI_Req_GetUnspentOuts new__req_params__get_unspent_outs( // used internally and by emscr async send impl string from_address_string, string sec_viewKey_string ); typedef std::function send__get_unspent_outs_fn_type; // struct LightwalletAPI_Req_GetRandomOuts { const vector amounts; const size_t count; // =mixin+1 }; LightwalletAPI_Req_GetRandomOuts new__req_params__get_random_outs( // used internally and by emscr async send impl vector &step1__using_outs ); typedef std::function send__get_random_outs_fn_type; // struct LightwalletAPI_Req_SubmitRawTx { // strings are NOT references, so they get copied, allowing scope of struct init not to be an issue const string address; const string view_key; const string tx; // serialized tx }; typedef std::function send__submit_raw_tx_fn_type; // // - Accessory types - Callbacks - Updates enum SendFunds_ProcessStep { // These codes have values for serialization fetchingLatestBalance = 1, calculatingFee = 2, fetchingDecoyOutputs = 3, constructingTransaction = 4, submittingTransaction = 5 }; typedef std::function send__status_update_fn_type; static inline string err_msg_from_err_code__send_funds_step(SendFunds_ProcessStep code) { switch (code) { case fetchingLatestBalance: return "Fetching latest balance."; case calculatingFee: return "Calculating fee."; case fetchingDecoyOutputs: return "Fetching decoy outputs."; case constructingTransaction: return "Constructing transaction."; // which may go back to .calculatingFee case submittingTransaction: return "Submitted transaction."; } } // - Accessory types - Callbacks - Routine completions struct SendFunds_Error_RetVals { optional explicit_errMsg; optional errCode; // if != noError, abort Send process // for display / information purposes on errCode=needMoreMoneyThanFound during step1: uint64_t spendable_balance; // (effectively but not the same as spendable_balance) uint64_t required_balance; // for display / information purposes on errCode=needMoreMoneyThanFound during step1 }; typedef std::function send__error_cb_fn_type; // struct SendFunds_Success_RetVals { uint64_t used_fee; uint64_t total_sent; // final_total_wo_fee + final_fee size_t mixin; optional final_payment_id; // will be filled if a payment id was passed in or an integrated address was used string signed_serialized_tx_string; string tx_hash_string; string tx_key_string; // this includes additional_tx_keys string tx_pub_key_string; // from get_tx_pub_key_from_extra() }; typedef std::function send__success_cb_fn_type; // // Response parsing struct LightwalletAPI_Res_GetUnspentOuts { optional err_msg; // OR optional per_byte_fee; optional> unspent_outs; }; struct LightwalletAPI_Res_GetRandomOuts { optional err_msg; // OR optional> mix_outs; }; LightwalletAPI_Res_GetUnspentOuts new__parsed_res__get_unspent_outs( const property_tree::ptree &res, const secret_key &sec_viewKey, const secret_key &sec_spendKey, const public_key &pub_spendKey ); LightwalletAPI_Res_GetRandomOuts new__parsed_res__get_random_outs( const property_tree::ptree &res ); // // - Routine entrypoint struct Async_SendFunds_Args { // TODO: add a way to pass native structures if available string from_address_string; string sec_viewKey_string; string sec_spendKey_string; string pub_spendKey_string; string to_address_string; optional payment_id_string; uint64_t sending_amount; bool is_sweeping; uint32_t simple_priority; send__get_unspent_outs_fn_type get_unspent_outs_fn; send__get_random_outs_fn_type get_random_outs_fn; send__submit_raw_tx_fn_type submit_raw_tx_fn; send__status_update_fn_type status_update_fn; send__error_cb_fn_type error_cb_fn; send__success_cb_fn_type success_cb_fn; // optional unlock_time; // default 0 optional nettype; }; void async__send_funds(Async_SendFunds_Args args); } #endif /* monero_send_routine_hpp */