@ -42,6 +42,14 @@ const JSBigInt = require('../cryptonote_utils/biginteger').BigInteger
//
const APPROXIMATE _INPUT _BYTES = 80 // used to choose when to stop adding outputs to a tx
//
function fixedMixin ( ) { return 9 ; }
function fixedRingsize ( ) { return fixedMixin ( ) + 1 ; }
exports . fixedMixin = fixedMixin ;
exports . fixedRingsize = fixedRingsize ;
//
function default _priority ( ) { return 2 ; } // aka .mlow or medium low
exports . default _priority = default _priority ;
//
function calculate _fee ( fee _per _kb _JSBigInt , numberOf _bytes , fee _multiplier )
{
const numberOf _kB _JSBigInt = new JSBigInt ( ( numberOf _bytes + 1023.0 ) / 1024.0 )
@ -49,29 +57,34 @@ function calculate_fee(fee_per_kb_JSBigInt, numberOf_bytes, fee_multiplier)
//
return fee
}
//
// Fee estimation for SendFunds
function calculate _fee _ _kb ( fee _per _kb _JSBigInt , numberOf _kb , fee _multiplier )
{
const numberOf _kB _JSBigInt = new JSBigInt ( numberOf _kb )
const fee = fee _per _kb _JSBigInt . multiply ( fee _multiplier ) . multiply ( numberOf _kB _JSBigInt )
//
return fee
}
const newer _multipliers = [ 1 , 4 , 20 , 166 ] ;
function fee _multiplier _for _priority ( priority _ _or0ForDefault ) {
const priority _as _idx = ! priority _ _or0ForDefault || priority _ _or0ForDefault == 0
? default _priority ( )
: priority _ _or0ForDefault ;
if ( priority _as _idx <= 0 || priority _as _idx > 4 ) {
throw "fee_multiplier_for_priority: simple_priority out of bounds"
}
return newer _multipliers [ priority _as _idx - 1 ]
}
function EstimatedTransaction _networkFee (
nonZero _mixin _int ,
feePerKB _JSBigInt ,
simple _priority
)
{
if ( simple _priority == 0 ) {
simple _priority = 2 ; // the default (TODO: read this from a domain)
}
if ( simple _priority <= 0 || simple _priority > 4 ) {
throw "EstimatedTransaction_networkFee: simple_priority out of bounds"
}
//
) {
const numberOf _inputs = 2 // this might change -- might select inputs
const numberOf _outputs = 1 /*dest*/ + 1 /*change*/ + 0 /*no mymonero fee presently*/
// TODO: update est tx size for bulletproofs
// TODO: normalize est tx size fn naming
const estimated _txSize = EstimatedTransaction _ringCT _txSize ( numberOf _inputs , nonZero _mixin _int , numberOf _outputs )
const fee _multiplier = newer _multipliers [ simple _priority - 1 ]
const estimated _fee = calculate _fee ( feePerKB _JSBigInt , estimated _txSize , fee _multiplier )
const estimated _fee = calculate _fee ( feePerKB _JSBigInt , estimated _txSize , fee _multiplier _for _priority ( simple _priority ) )
//
return estimated _fee
}
@ -81,8 +94,7 @@ function EstimatedTransaction_ringCT_txSize(
numberOf _inputs ,
mixin _int ,
numberOf _outputs
)
{
) {
var size = 0 ;
// tx prefix
// first few bytes
@ -128,8 +140,8 @@ function SendFunds(
wallet _ _public _keys ,
hostedMoneroAPIClient ,
monero _openalias _utils ,
mixin ,
payment _id ,
simple _priority ,
success _fn ,
// success_fn: (
// moneroReady_targetDescription_address?,
@ -142,10 +154,9 @@ function SendFunds(
// failWithErr_fn: (
// err
// )
)
{
) {
// arg sanitization
mixin = parseInt ( mixin )
const mixin = fixedMixin ( ) ;
//
// some callback trampoline function declarations…
function _ _trampolineFor _success (
@ -274,7 +285,7 @@ function SendFunds(
_ _trampolineFor _err _withErr ( err )
return
}
console . log ( "Received dynamic per kb fee" , dynamic_feePerKB _JSBigInt )
console . log ( "Received dynamic per kb fee" , monero_utils . formatMoneySymbol ( dynamic_feePerKB _JSBigInt ) )
_proceedTo _constructFundTransferListAndSendFundsByUsingUnusedUnspentOutsForMixin (
moneroReady _targetDescription _address ,
totalAmountWithoutFee _JSBigInt ,
@ -293,13 +304,12 @@ function SendFunds(
final _ _pid _encrypt ,
unusedOuts ,
dynamic _feePerKB _JSBigInt
)
{
) {
// status: constructing transaction…
const feePerKB _JSBigInt = dynamic _feePerKB _JSBigInt
// Transaction will need at least 1KB fee ( 13KB for RingCT)
const network _minimumTXSize _kb = isRingCT ? 13 : 1
var network _minimumFee = feePerKB _JSBigInt . multiply ( network _minimumTXSize _kb )
// Transaction will need at least 1KB fee ( or 13KB for RingCT)
const network _minimumTXSize _kb = /*isRingCT ? */ 13 /* : 1*/
const network _minimumFee = calculate _fee _ _kb ( feePerKB _JSBigInt , network _minimumTXSize _kb , fee _multiplier _for _priority ( simple _priority ) )
// ^-- now we're going to try using this minimum fee but the codepath has to be able to be re-entered if we find after constructing the whole tx that it is larger in kb than the minimum fee we're attempting to send it off with
_ _reenterable _constructFundTransferListAndSendFunds _findingLowestNetworkFee (
moneroReady _targetDescription _address ,
@ -321,7 +331,6 @@ function SendFunds(
passedIn _attemptAt _network _minimumFee
)
{ // Now we need to establish some values for balance validation and to construct the transaction
console . log ( "Entered re-enterable tx building codepath…" , unusedOuts )
var attemptAt _network _minimumFee = passedIn _attemptAt _network _minimumFee // we may change this if isRingCT
// const hostingService_chargeAmount = hostedMoneroAPIClient.HostingServiceChargeFor_transactionWithNetworkFee(attemptAt_network_minimumFee)
var totalAmountIncludingFees = totalAmountWithoutFee _JSBigInt . add ( attemptAt _network _minimumFee ) /*.add(hostingService_chargeAmount) NOTE service fee removed for now */
@ -504,7 +513,7 @@ function SendFunds(
numKB ++
}
console . log ( txBlobBytes + " bytes <= " + numKB + " KB (current fee: " + monero _utils . formatMoneyFull ( attemptAt _network _minimumFee ) + ")" )
const feeActuallyNeededByNetwork = feePerKB_JSBigInt . multiply ( numKB )
const feeActuallyNeededByNetwork = calculate_fee _ _kb ( feePerKB _JSBigInt , numKB , fee _multiplier _for _priority ( simple _priority ) )
// if we need a higher fee
if ( feeActuallyNeededByNetwork . compare ( attemptAt _network _minimumFee ) > 0 ) {
console . log ( "💬 Need to reconstruct the tx with enough of a network fee. Previous fee: " + monero _utils . formatMoneyFull ( attemptAt _network _minimumFee ) + " New fee: " + monero _utils . formatMoneyFull ( feeActuallyNeededByNetwork ) )