Created
June 3, 2017 10:14
-
-
Save you21979/cd6bb8d7e3b0a18621514bc26a830173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prepareFee(): Promise<Object> { | |
const multiplier = instructions.signersCount === undefined ? 1 : | |
instructions.signersCount + 1 | |
if (instructions.fee !== undefined) { | |
txJSON.Fee = scaleValue(common.xrpToDrops(instructions.fee), multiplier) | |
return Promise.resolve(txJSON) | |
} | |
const cushion = api._feeCushion | |
return common.serverInfo.getFee(api.connection, cushion).then(fee => { | |
return api.connection.getFeeRef().then(feeRef => { | |
const extraFee = | |
(txJSON.TransactionType !== 'EscrowFinish' || | |
txJSON.Fulfillment === undefined) ? 0 : | |
(cushion * feeRef * (32 + Math.floor( | |
new Buffer(txJSON.Fulfillment, 'hex').length / 16))) | |
const feeDrops = common.xrpToDrops(fee) | |
if (instructions.maxFee !== undefined) { | |
const maxFeeDrops = common.xrpToDrops(instructions.maxFee) | |
const normalFee = scaleValue(feeDrops, multiplier, extraFee) | |
txJSON.Fee = BigNumber.min(normalFee, maxFeeDrops).toString(); | |
} else { | |
txJSON.Fee = scaleValue(feeDrops, multiplier, extraFee) | |
} | |
return txJSON | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment