@ -67,65 +67,6 @@ function default_priority() {
} // aka .low
exports . default _priority = default _priority ;
//
function estimateRctSize ( inputs , mixin , outputs , extra _size , bulletproof )
{
// keeping this in JS instead of C++ for now b/c it's much faster to access, and we don't have to make it asynchronous by waiting for the module to load
bulletproof = bulletproof == true ? true : false
extra _size = extra _size || 40
//
var size = 0 ;
// tx prefix
// first few bytes
size += 1 + 6 ;
size += inputs * ( 1 + 6 + ( mixin + 1 ) * 2 + 32 ) ;
// vout
size += outputs * ( 6 + 32 ) ;
// extra
size += extra _size ;
// rct signatures
// type
size += 1 ;
// rangeSigs
if ( bulletproof )
size += ( ( 2 * 6 + 4 + 5 ) * 32 + 3 ) * outputs ;
else
size += ( 2 * 64 * 32 + 32 + 64 * 32 ) * outputs ;
// MGs
size += inputs * ( 64 * ( mixin + 1 ) + 32 ) ;
// mixRing - not serialized, can be reconstructed
/* size += 2 * 32 * (mixin+1) * inputs; */
// pseudoOuts
size += 32 * inputs ;
// ecdhInfo
size += 2 * 32 * outputs ;
// outPk - only commitment is saved
size += 32 * outputs ;
// txnFee
size += 4 ;
// const logStr = `estimated rct tx size for ${inputs} at mixin ${mixin} and ${outputs} : ${size} (${((32 * inputs/*+1*/) + 2 * 32 * (mixin+1) * inputs + 32 * outputs)}) saved)`
// console.log(logStr)
return size ;
} ;
function calculate _fee ( fee _per _kb _JSBigInt , numberOf _bytes , fee _multiplier ) {
const numberOf _kB _JSBigInt = new JSBigInt (
( numberOf _bytes + 1023.0 ) / 1024.0 ,
) ; // i.e. ceil
//
return calculate _fee _ _kb (
fee _per _kb _JSBigInt ,
numberOf _kB _JSBigInt ,
fee _multiplier ,
) ;
}
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 final _priorityInt =
@ -182,7 +123,7 @@ function SendFunds(
// tx_key?,
// mixin?,
// )
failWithErr _fn ,
failWithErr _fn
// failWithErr_fn: (
// err
// )
@ -382,11 +323,14 @@ function SendFunds(
const feePerKB _JSBigInt = dynamic _feePerKB _JSBigInt ;
// 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 ) ,
) ;
const network _minimumTXSize _bytes = network _minimumTXSize _kb * 1000 // B -> kB
const network _minimumFee = new JSBigInt (
monero _utils . calculate _fee (
"" + feePerKB _JSBigInt ,
network _minimumTXSize _bytes ,
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 ,
@ -438,10 +382,14 @@ function SendFunds(
var usingOutsAmount = usableOutputsAndAmounts . usingOutsAmount ;
var remaining _unusedOuts = usableOutputsAndAmounts . remaining _unusedOuts ; // this is a copy of the pre-mutation usingOuts
if ( /*usingOuts.length > 1 &&*/ isRingCT ) {
var newNeededFee = calculate _fee (
feePerKB _JSBigInt ,
estimateRctSize ( usingOuts . length , mixin , 2 ) ,
fee _multiplier _for _priority ( simple _priority ) ,
var newNeededFee = new JSBigInt (
monero _utils . calculate _fee (
"" + feePerKB _JSBigInt ,
monero _utils . estimate _rct _tx _size (
usingOuts . length , mixin , 2
) ,
fee _multiplier _for _priority ( simple _priority )
)
) ;
// if newNeededFee < neededFee, use neededFee instead (should only happen on the 2nd or later times through (due to estimated fee being too low))
if ( newNeededFee . compare ( attemptAt _network _minimumFee ) < 0 ) {
@ -491,14 +439,14 @@ function SendFunds(
JSON . stringify ( out ) ,
) ;
// and recalculate invalidated values
newNeededFee = calculate _fee (
feePerKB_JSBigInt ,
estimateRctSize (
usingOuts. length ,
mixin ,
2 ,
) ,
fee _multiplier _for _priority ( simple _priority ) ,
newNeededFee = new JSBigInt (
monero_utils . calculate _fee (
"" + feePerKB _JSBigInt ,
monero_utils . estimate _rct _tx _size (
usingOuts . length , mixin , 2
) ,
fee _multiplier _for _priority ( simple _priority )
)
) ;
totalAmountIncludingFees = totalAmountWithoutFee _JSBigInt . add (
newNeededFee ,
@ -621,17 +569,17 @@ function SendFunds(
}
console . log (
txBlobBytes +
" bytes <= " +
numKB +
" KB (current fee: " +
" bytes; current fee: " +
monero _amount _format _utils . formatMoneyFull ( attemptAt _network _minimumFee ) +
")" ,
) ;
const feeActuallyNeededByNetwork = calculate _fee _ _kb (
feePerKB _JSBigInt ,
numKB ,
fee _multiplier _for _priority ( simple _priority ) ,
"" ,
) ;
const feeActuallyNeededByNetwork = new JSBigInt (
monero _utils . calculate _fee (
"" + feePerKB _JSBigInt ,
txBlobBytes ,
fee _multiplier _for _priority ( simple _priority )
)
)
// if we need a higher fee
if (
feeActuallyNeededByNetwork . compare (