pull/29/head
parent
5f54c5aa8f
commit
22bb35bf01
@ -1 +1 @@
|
||||
Subproject commit 40db201ddff523365b1625135a69e2ed80cce486
|
||||
Subproject commit 34fa840ba48dcd1cdd4e653050e950b58dfbf524
|
@ -0,0 +1,131 @@
|
||||
//
|
||||
// monero_key_image_utils.cpp
|
||||
// MyMonero
|
||||
//
|
||||
// Created by Paul Shapiro on 1/2/18.
|
||||
// Copyright (c) 2014-2018, 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.
|
||||
//
|
||||
//
|
||||
#include "monero_key_image_utils.hpp"
|
||||
//
|
||||
using namespace crypto;
|
||||
using namespace cryptonote;
|
||||
//
|
||||
bool monero_key_image_utils::new__key_image(
|
||||
const crypto::public_key& account_pub_spend_key,
|
||||
const crypto::secret_key& account_sec_spend_key,
|
||||
const crypto::secret_key& account_sec_view_key,
|
||||
const crypto::public_key& tx_public_key,
|
||||
uint64_t out_index,
|
||||
KeyImageRetVals &retVals
|
||||
) {
|
||||
retVals = {};
|
||||
//
|
||||
bool r = false;
|
||||
//
|
||||
// "Subaddresses aren't supported in mymonero/openmonero yet. Roll out the original scheme:
|
||||
// compute D = a*R
|
||||
// compute P = Hs(D || i)*G + B
|
||||
// compute x = Hs(D || i) + b (and check if P==x*G)
|
||||
// compute I = x*Hp(P)"
|
||||
crypto::key_derivation derivation;
|
||||
r = crypto::generate_key_derivation(tx_public_key, account_sec_view_key, derivation);
|
||||
if (!r) {
|
||||
retVals.did_error = true;
|
||||
std::stringstream ss{};
|
||||
ss << "failed to generate_key_derivation(" << tx_public_key << ", " << account_sec_view_key << ")";
|
||||
retVals.err_string = ss.str();
|
||||
//
|
||||
return false;
|
||||
}
|
||||
cryptonote::keypair in_ephemeral;
|
||||
r = crypto::derive_public_key(derivation, out_index, account_pub_spend_key, in_ephemeral.pub);
|
||||
if (!r) {
|
||||
retVals.did_error = true;
|
||||
std::stringstream ss{};
|
||||
ss << "failed to derive_public_key (" << derivation << ", " << out_index << ", " << account_pub_spend_key << ")";
|
||||
retVals.err_string = ss.str();
|
||||
//
|
||||
return false;
|
||||
}
|
||||
crypto::derive_secret_key(derivation, out_index, account_sec_spend_key, in_ephemeral.sec);
|
||||
crypto::public_key out_pkey_test;
|
||||
r = crypto::secret_key_to_public_key(in_ephemeral.sec, out_pkey_test);
|
||||
if (!r) {
|
||||
retVals.did_error = true;
|
||||
std::stringstream ss{};
|
||||
ss << "failed to secret_key_to_public_key(" << in_ephemeral.sec << ")";
|
||||
retVals.err_string = ss.str();
|
||||
//
|
||||
return false;
|
||||
}
|
||||
if (in_ephemeral.pub != out_pkey_test) {
|
||||
retVals.did_error = true;
|
||||
retVals.err_string = "derived secret key doesn't match derived public key";
|
||||
//
|
||||
return false;
|
||||
}
|
||||
crypto::generate_key_image(in_ephemeral.pub, in_ephemeral.sec, retVals.calculated_key_image);
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
//+ (NSString *)new_keyImageFrom_tx_pub_key:(NSString *)tx_pub_key_NSString
|
||||
//sec_spendKey:(NSString *)sec_spendKey_NSString
|
||||
//sec_viewKey:(NSString *)sec_viewKey_NSString
|
||||
//pub_spendKey:(NSString *)pub_spendKey_NSString
|
||||
//out_index:(uint64_t)out_index
|
||||
//{
|
||||
// crypto::secret_key sec_viewKey{};
|
||||
// crypto::secret_key sec_spendKey{};
|
||||
// crypto::public_key pub_spendKey{};
|
||||
// crypto::public_key tx_pub_key{};
|
||||
// { // Would be nice to find a way to avoid converting these back and forth
|
||||
// bool r = false;
|
||||
// r = string_tools::hex_to_pod(std::string(sec_viewKey_NSString.UTF8String), sec_viewKey);
|
||||
// NSAssert(r, @"Invalid secret view key");
|
||||
// r = string_tools::hex_to_pod(std::string(sec_spendKey_NSString.UTF8String), sec_spendKey);
|
||||
// NSAssert(r, @"Invalid secret spend key");
|
||||
// r = string_tools::hex_to_pod(std::string(pub_spendKey_NSString.UTF8String), pub_spendKey);
|
||||
// NSAssert(r, @"Invalid public spend key");
|
||||
// r = string_tools::hex_to_pod(std::string(tx_pub_key_NSString.UTF8String), tx_pub_key);
|
||||
// NSAssert(r, @"Invalid tx pub key");
|
||||
// }
|
||||
// monero_key_image_utils::KeyImageRetVals retVals;
|
||||
// {
|
||||
// bool r = monero_key_image_utils::new__key_image(pub_spendKey, sec_spendKey, sec_viewKey, tx_pub_key, out_index, retVals);
|
||||
// if (!r) {
|
||||
// return nil; // TODO: return error string? (unwrap optional)
|
||||
// }
|
||||
// }
|
||||
// std::string key_image_hex_string = string_tools::pod_to_hex(retVals.calculated_key_image);
|
||||
// NSString *key_image_hex_NSString = [NSString stringWithUTF8String:key_image_hex_string.c_str()];
|
||||
// //
|
||||
// return key_image_hex_NSString;
|
||||
//}
|
@ -0,0 +1,60 @@
|
||||
//
|
||||
// monero_key_image_utils.hpp
|
||||
// MyMonero
|
||||
//
|
||||
// Created by Paul Shapiro on 1/2/18.
|
||||
// Copyright (c) 2014-2018, 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_key_image_utils_hpp
|
||||
#define monero_key_image_utils_hpp
|
||||
//
|
||||
#include "crypto.h"
|
||||
#include "cryptonote_basic.h"
|
||||
//
|
||||
using namespace tools;
|
||||
#include "tools__ret_vals.hpp"
|
||||
//
|
||||
namespace monero_key_image_utils
|
||||
{
|
||||
struct KeyImageRetVals: RetVals_base
|
||||
{
|
||||
crypto::key_image calculated_key_image;
|
||||
};
|
||||
bool new__key_image(
|
||||
const crypto::public_key& account_pub_spend_key,
|
||||
const crypto::secret_key& account_sec_spend_key,
|
||||
const crypto::secret_key& account_sec_view_key,
|
||||
const crypto::public_key& tx_public_key,
|
||||
uint64_t out_index,
|
||||
KeyImageRetVals &KeyImageRetVals
|
||||
);
|
||||
}
|
||||
//
|
||||
#endif /* monero_key_image_utils_hpp */
|
@ -0,0 +1,233 @@
|
||||
//
|
||||
// monero_transfer_utils.cpp
|
||||
// Copyright © 2018 MyMonero. All rights reserved.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
#include "monero_transfer_utils.hpp"
|
||||
//#include "monero_fork_rules.hpp"
|
||||
//#include "wallet_errors.h
|
||||
//
|
||||
//using namespace std;
|
||||
//using namespace crypto;
|
||||
//using namespace epee;
|
||||
//using namespace cryptonote;
|
||||
//using namespace tools; // for error::
|
||||
using namespace monero_transfer_utils;
|
||||
//using namespace monero_fork_rules;
|
||||
//
|
||||
//
|
||||
// monero_transfer_utils - General functions
|
||||
uint64_t monero_transfer_utils::get_upper_transaction_size_limit(uint64_t upper_transaction_size_limit__or_0_for_default, use_fork_rules_fn_type use_fork_rules_fn)
|
||||
{
|
||||
if (upper_transaction_size_limit__or_0_for_default > 0)
|
||||
return upper_transaction_size_limit__or_0_for_default;
|
||||
uint64_t full_reward_zone = use_fork_rules_fn(5, 10) ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : use_fork_rules_fn(2, 10) ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 : CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1;
|
||||
return full_reward_zone - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
|
||||
}
|
||||
uint64_t monero_transfer_utils::get_fee_multiplier(
|
||||
uint32_t priority,
|
||||
uint32_t default_priority,
|
||||
int fee_algorithm,
|
||||
use_fork_rules_fn_type use_fork_rules_fn
|
||||
) {
|
||||
static const uint64_t old_multipliers[3] = {1, 2, 3};
|
||||
static const uint64_t new_multipliers[3] = {1, 20, 166};
|
||||
static const uint64_t newer_multipliers[4] = {1, 4, 20, 166};
|
||||
|
||||
if (fee_algorithm == -1)
|
||||
fee_algorithm = get_fee_algorithm(use_fork_rules_fn);
|
||||
|
||||
// 0 -> default (here, x1 till fee algorithm 2, x4 from it)
|
||||
if (priority == 0)
|
||||
priority = default_priority;
|
||||
if (priority == 0)
|
||||
{
|
||||
if (fee_algorithm >= 2)
|
||||
priority = 2;
|
||||
else
|
||||
priority = 1;
|
||||
}
|
||||
|
||||
// 1 to 3/4 are allowed as priorities
|
||||
uint32_t max_priority = (fee_algorithm >= 2) ? 4 : 3;
|
||||
if (priority >= 1 && priority <= max_priority)
|
||||
{
|
||||
switch (fee_algorithm)
|
||||
{
|
||||
case 0: return old_multipliers[priority-1];
|
||||
case 1: return new_multipliers[priority-1];
|
||||
case 2: return newer_multipliers[priority-1];
|
||||
default: THROW_WALLET_EXCEPTION_IF (true, error::invalid_priority);
|
||||
}
|
||||
}
|
||||
|
||||
THROW_WALLET_EXCEPTION_IF (false, error::invalid_priority);
|
||||
return 1;
|
||||
}
|
||||
//
|
||||
int monero_transfer_utils::get_fee_algorithm(use_fork_rules_fn_type use_fork_rules_fn)
|
||||
{
|
||||
// changes at v3 and v5
|
||||
if (use_fork_rules_fn(5, 0))
|
||||
return 2;
|
||||
if (use_fork_rules_fn(3, -720 * 14))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
size_t monero_transfer_utils::estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof)
|
||||
{
|
||||
size_t size = 0;
|
||||
|
||||
// tx prefix
|
||||
|
||||
// first few bytes
|
||||
size += 1 + 6;
|
||||
|
||||
// vin
|
||||
size += n_inputs * (1+6+(mixin+1)*2+32);
|
||||
|
||||
// vout
|
||||
size += n_outputs * (6+32);
|
||||
|
||||
// extra
|
||||
size += extra_size;
|
||||
|
||||
// rct signatures
|
||||
|
||||
// type
|
||||
size += 1;
|
||||
|
||||
// rangeSigs
|
||||
if (bulletproof)
|
||||
size += ((2*6 + 4 + 5)*32 + 3) * n_outputs;
|
||||
else
|
||||
size += (2*64*32+32+64*32) * n_outputs;
|
||||
|
||||
// MGs
|
||||
size += n_inputs * (64 * (mixin+1) + 32);
|
||||
|
||||
// mixRing - not serialized, can be reconstructed
|
||||
/* size += 2 * 32 * (mixin+1) * n_inputs; */
|
||||
|
||||
// pseudoOuts
|
||||
size += 32 * n_inputs;
|
||||
// ecdhInfo
|
||||
size += 2 * 32 * n_outputs;
|
||||
// outPk - only commitment is saved
|
||||
size += 32 * n_outputs;
|
||||
// txnFee
|
||||
size += 4;
|
||||
|
||||
LOG_PRINT_L2("estimated rct tx size for " << n_inputs << " with ring size " << (mixin+1) << " and " << n_outputs << ": " << size << " (" << ((32 * n_inputs/*+1*/) + 2 * 32 * (mixin+1) * n_inputs + 32 * n_outputs) << " saved)");
|
||||
return size;
|
||||
}
|
||||
size_t monero_transfer_utils::estimate_tx_size(bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof)
|
||||
{
|
||||
if (use_rct)
|
||||
return estimate_rct_tx_size(n_inputs, mixin, n_outputs + 1, extra_size, bulletproof);
|
||||
else
|
||||
return n_inputs * (mixin+1) * APPROXIMATE_INPUT_BYTES + extra_size;
|
||||
}
|
||||
//
|
||||
uint64_t monero_transfer_utils::calculate_fee(uint64_t fee_per_kb, size_t bytes, uint64_t fee_multiplier)
|
||||
{
|
||||
uint64_t kB = (bytes + 1023) / 1024;
|
||||
return kB * fee_per_kb * fee_multiplier;
|
||||
}
|
||||
uint64_t monero_transfer_utils::calculate_fee(uint64_t fee_per_kb, const cryptonote::blobdata &blob, uint64_t fee_multiplier)
|
||||
{
|
||||
return calculate_fee(fee_per_kb, blob.size(), fee_multiplier);
|
||||
}
|
||||
//
|
||||
// Transfer parsing/derived properties
|
||||
bool monero_transfer_utils::is_transfer_unlocked(
|
||||
uint64_t unlock_time,
|
||||
uint64_t block_height,
|
||||
uint64_t blockchain_size, /* extracting wallet2->m_blockchain.size() / m_local_bc_height */
|
||||
bool is_testnet
|
||||
) {
|
||||
if(!is_tx_spendtime_unlocked(unlock_time, block_height, blockchain_size, is_testnet))
|
||||
return false;
|
||||
|
||||
if(block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE > blockchain_size)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool monero_transfer_utils::is_tx_spendtime_unlocked(
|
||||
uint64_t unlock_time,
|
||||
uint64_t block_height,
|
||||
uint64_t blockchain_size,
|
||||
bool is_testnet
|
||||
) {
|
||||
if(unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER)
|
||||
{
|
||||
//interpret as block index
|
||||
if(block_height-1 + CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS >= unlock_time)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}else
|
||||
{
|
||||
//interpret as time
|
||||
uint64_t current_time = static_cast<uint64_t>(time(NULL));
|
||||
// XXX: this needs to be fast, so we'd need to get the starting heights
|
||||
// from the daemon to be correct once voting kicks in
|
||||
uint64_t v2height = is_testnet ? 624634 : 1009827;
|
||||
uint64_t leeway = block_height < v2height ? CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1 : CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2;
|
||||
if(current_time + leeway >= unlock_time)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t monero_transfer_utils::fixed_ringsize()
|
||||
{
|
||||
return 7; // TODO/FIXME: temporary…… for lightwallet code!
|
||||
}
|
||||
uint32_t monero_transfer_utils::fixed_mixinsize()
|
||||
{
|
||||
return monero_transfer_utils::fixed_ringsize() - 1;
|
||||
}
|
||||
std::string monero_transfer_utils::new_dummy_address_string_for_rct_tx(bool isTestnet)
|
||||
{
|
||||
cryptonote::account_base account;
|
||||
account.generate();
|
||||
//
|
||||
return account.get_public_address_str(isTestnet ? cryptonote::TESTNET : cryptonote::MAINNET);
|
||||
}
|
||||
uint32_t monero_transfer_utils::default_priority()
|
||||
{
|
||||
return 1; // lowest (TODO: declare)
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
//
|
||||
// monero_transfer_utils.hpp
|
||||
// Copyright (c) 2014-2018, 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_transfer_utils_hpp
|
||||
#define monero_transfer_utils_hpp
|
||||
//
|
||||
#include "string_tools.h"
|
||||
#include "crypto.h"
|
||||
#include "cryptonote_basic.h"
|
||||
#include "cryptonote_format_utils.h"
|
||||
#include "cryptonote_tx_utils.h"
|
||||
//
|
||||
using namespace tools;
|
||||
#include "tools__ret_vals.hpp"
|
||||
//
|
||||
// used to choose when to stop adding outputs to a tx
|
||||
#define APPROXIMATE_INPUT_BYTES 80
|
||||
// used to target a given block size (additional outputs may be added on top to build fee)
|
||||
#define TX_SIZE_TARGET(bytes) (bytes*2/3)
|
||||
//
|
||||
namespace monero_transfer_utils
|
||||
{
|
||||
//
|
||||
typedef std::function<bool(uint8_t, int64_t)> use_fork_rules_fn_type;
|
||||
//
|
||||
uint64_t get_upper_transaction_size_limit(uint64_t upper_transaction_size_limit__or_0_for_default, use_fork_rules_fn_type use_fork_rules_fn);
|
||||
uint64_t get_fee_multiplier(uint32_t priority, uint32_t default_priority, int fee_algorithm, use_fork_rules_fn_type use_fork_rules_fn);
|
||||
int get_fee_algorithm(use_fork_rules_fn_type use_fork_rules_fn);
|
||||
//
|
||||
uint64_t calculate_fee(uint64_t fee_per_kb, size_t bytes, uint64_t fee_multiplier);
|
||||
uint64_t calculate_fee(uint64_t fee_per_kb, const cryptonote::blobdata &blob, uint64_t fee_multiplier);
|
||||
//
|
||||
size_t estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof);
|
||||
size_t estimate_tx_size(bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof);
|
||||
//
|
||||
bool is_transfer_unlocked(uint64_t unlock_time, uint64_t block_height, uint64_t blockchain_size, bool is_testnet = false);
|
||||
bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t block_height, uint64_t blockchain_size, bool is_testnet = false);
|
||||
//
|
||||
uint32_t fixed_ringsize(); // not mixinsize, which would be ringsize-1
|
||||
uint32_t fixed_mixinsize(); // not ringsize, which would be mixinsize+1
|
||||
//
|
||||
std::string new_dummy_address_string_for_rct_tx(bool isTestnet = false);
|
||||
//
|
||||
uint32_t default_priority();
|
||||
}
|
||||
|
||||
#endif /* monero_transfer_utils_hpp */
|
Loading…
Reference in new issue