Autofills AccountDelete Fee w/ reserve_inc_xrp (#1639)

* fix: fetch Owner Reserves from ledger
This commit is contained in:
Nathan Nichols
2021-09-24 12:09:54 -07:00
committed by Mayukha Vadari
parent 1747b31a02
commit b3a72588ea
2 changed files with 25 additions and 5 deletions

View File

@@ -12,10 +12,8 @@ import { Transaction } from '../models/transactions'
import setTransactionFlagsToNumber from '../models/utils/flags' import setTransactionFlagsToNumber from '../models/utils/flags'
import { xrpToDrops } from '../utils' import { xrpToDrops } from '../utils'
// 20 drops // Expire unconfirmed transactions after 20 ledger versions, approximately 1 minute, by default
const LEDGER_OFFSET = 20 const LEDGER_OFFSET = 20
// 5 XRP
const ACCOUNT_DELETE_FEE = 5000000
interface ClassicAccountAndTag { interface ClassicAccountAndTag {
classicAccount: string classicAccount: string
tag: number | false | undefined tag: number | false | undefined
@@ -139,6 +137,17 @@ async function setNextValidSequenceNumber(
tx.Sequence = data.result.account_data.Sequence tx.Sequence = data.result.account_data.Sequence
} }
async function fetchAccountDeleteFee(client: Client): Promise<BigNumber> {
const response = await client.request({ command: 'server_state' })
const fee = response.result.state.validated_ledger?.reserve_inc
if (fee == null) {
return Promise.reject(new Error('Could not fetch Owner Reserve.'))
}
return new BigNumber(fee)
}
async function calculateFeePerTransactionType( async function calculateFeePerTransactionType(
client: Client, client: Client,
tx: Transaction, tx: Transaction,
@@ -162,7 +171,7 @@ async function calculateFeePerTransactionType(
// AccountDelete Transaction // AccountDelete Transaction
if (tx.TransactionType === 'AccountDelete') { if (tx.TransactionType === 'AccountDelete') {
baseFee = new BigNumber(ACCOUNT_DELETE_FEE) baseFee = await fetchAccountDeleteFee(client)
} }
// Multi-signed Transaction // Multi-signed Transaction

View File

@@ -140,6 +140,17 @@ describe('client.autofill', function () {
} }
this.mockRippled.addResponse('account_info', rippled.account_info.normal) this.mockRippled.addResponse('account_info', rippled.account_info.normal)
this.mockRippled.addResponse('ledger', rippled.ledger.normal) this.mockRippled.addResponse('ledger', rippled.ledger.normal)
this.mockRippled.addResponse('server_state', {
status: 'success',
type: 'response',
result: {
state: {
validated_ledger: {
reserve_inc: 2000000,
},
},
},
})
this.mockRippled.addResponse('server_info', rippled.server_info.normal) this.mockRippled.addResponse('server_info', rippled.server_info.normal)
this.mockRippled.addResponse( this.mockRippled.addResponse(
'account_objects', 'account_objects',
@@ -147,7 +158,7 @@ describe('client.autofill', function () {
) )
const txResult = await this.client.autofill(tx) const txResult = await this.client.autofill(tx)
assert.strictEqual(txResult.Fee, '5000000') assert.strictEqual(txResult.Fee, '2000000')
}) })
it('should autofill Fee of an EscrowFinish transaction with signersCount', async function () { it('should autofill Fee of an EscrowFinish transaction with signersCount', async function () {