@ -52,7 +52,7 @@ 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 )
const numberOf _kB _JSBigInt = new JSBigInt ( ( numberOf _bytes + 1023.0 ) / 1024.0 ) // i.e. ceil
const fee = fee _per _kb _JSBigInt . multiply ( fee _multiplier ) . multiply ( numberOf _kB _JSBigInt )
//
return fee
@ -83,51 +83,13 @@ function EstimatedTransaction_networkFee(
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 _tx Size( numberOf _inputs , nonZero _mixin _int , numberOf _outputs )
const estimated _txSize = monero_utils . estimateRct Size( numberOf _inputs , nonZero _mixin _int , numberOf _outputs )
const estimated _fee = calculate _fee ( feePerKB _JSBigInt , estimated _txSize , fee _multiplier _for _priority ( simple _priority ) )
//
return estimated _fee
}
exports . EstimatedTransaction _networkFee = EstimatedTransaction _networkFee
//
function EstimatedTransaction _ringCT _txSize (
numberOf _inputs ,
mixin _int ,
numberOf _outputs
) {
var size = 0 ;
// tx prefix
// first few bytes
size += 1 + 6 ;
size += numberOf _inputs * ( 1 + 6 + ( mixin _int + 1 ) * 3 + 32 ) ; // original implementation is *2+32 but luigi1111 said change 2 to 3
// vout
size += numberOf _outputs * ( 6 + 32 ) ;
// extra
size += 40 ;
// rct signatures
// type
size += 1 ;
// rangeSigs
size += ( 2 * 64 * 32 + 32 + 64 * 32 ) * numberOf _outputs ;
// MGs
size += numberOf _inputs * ( 32 * ( mixin _int + 1 ) + 32 ) ;
// mixRing - not serialized, can be reconstructed
/* size += 2 * 32 * (mixin_int+1) * numberOf_inputs; */
// pseudoOuts
size += 32 * numberOf _inputs ;
// ecdhInfo
size += 2 * 32 * numberOf _outputs ;
// outPk - only commitment is saved
size += 32 * numberOf _outputs ;
// txnFee
size += 4 ;
// const logStr = `estimated rct tx size for ${numberOf_inputs} at mixin ${mixin_int} and ${numberOf_outputs} : ${size} (${((32 * numberOf_inputs/*+1*/) + 2 * 32 * (mixin_int+1) * numberOf_inputs + 32 * numberOf_outputs)}) saved)`
// console.log(logStr)
return size ;
}
//
//
// Actually sending funds
//
function SendFunds (
@ -329,8 +291,7 @@ function SendFunds(
unusedOuts ,
feePerKB _JSBigInt ,
passedIn _attemptAt _network _minimumFee
)
{ // Now we need to establish some values for balance validation and to construct the transaction
) { // Now we need to establish some values for balance validation and to construct the transaction
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 */
@ -345,7 +306,11 @@ function SendFunds(
var remaining _unusedOuts = usableOutputsAndAmounts . remaining _unusedOuts // this is a copy of the pre-mutation usingOuts
if ( isRingCT ) {
if ( usingOuts . length > 1 ) {
var newNeededFee = new JSBigInt ( Math . ceil ( monero _utils . estimateRctSize ( usingOuts . length , mixin , 2 ) / 1024 ) ) . multiply ( feePerKB _JSBigInt )
var newNeededFee = calculate _fee (
feePerKB _JSBigInt ,
monero _utils . estimateRctSize ( usingOuts . length , mixin , 2 ) ,
fee _multiplier _for _priority ( simple _priority )
)
totalAmountIncludingFees = totalAmountWithoutFee _JSBigInt . add ( newNeededFee )
// add outputs 1 at a time till we either have them all or can meet the fee
while ( usingOutsAmount . compare ( totalAmountIncludingFees ) < 0 && remaining _unusedOuts . length > 0 ) {
@ -353,9 +318,13 @@ function SendFunds(
usingOuts . push ( out )
usingOutsAmount = usingOutsAmount . add ( out . amount )
console . log ( "Using output: " + monero _utils . formatMoney ( out . amount ) + " - " + JSON . stringify ( out ) )
newNeededFee = new JSBigInt (
Math . ceil ( monero _utils . estimateRctSize ( usingOuts . length , mixin , 2 ) / 1024 )
) . multiply ( feePerKB _JSBigInt )
//
// and recalculate invalidated values
newNeededFee = calculate _fee (
feePerKB _JSBigInt ,
monero _utils . estimateRctSize ( usingOuts . length , mixin , 2 ) ,
fee _multiplier _for _priority ( simple _priority )
)
totalAmountIncludingFees = totalAmountWithoutFee _JSBigInt . add ( newNeededFee )
}
console . log ( "New fee: " + monero _utils . formatMoneySymbol ( newNeededFee ) + " for " + usingOuts . length + " inputs" )