Skip to content

Commit

Permalink
fix XRP ledger index
Browse files Browse the repository at this point in the history
  • Loading branch information
ssramko committed Dec 13, 2021
1 parent 4a67ad9 commit 7fcd19e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/blockchain/xrp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, post } from '../connector/tatum'
import {get, post} from '../connector/tatum'
import {TransactionHash} from '../model'

/**
Expand All @@ -9,14 +9,14 @@ export const xrpGetFee = async (): Promise<{ drops: { base_fee: number } }> => g
/**
* For more details, see <a href="https://tatum.io/apidoc#operation/XrpGetAccountInfo" target="_blank">Tatum API documentation</a>
*/
export const xrpGetAccountInfo = async (account: string): Promise<{ ledger_current_index: number, account_data: { Sequence: number } }> =>
get(`/v3/xrp/account/${account}`)
export const xrpGetAccountInfo = async (account: string): Promise<{ ledger_current_index: number, ledger_index: number, account_data: { Sequence: number } }> =>
get(`/v3/xrp/account/${account}`)

/**
* For more details, see <a href="https://tatum.io/apidoc#operation/XrpBroadcast" target="_blank">Tatum API documentation</a>
*/
export const xrpBroadcast = async (txData: string, signatureId?: string): Promise<TransactionHash> =>
post(`/v3/xrp/broadcast`, { txData, signatureId })
post(`/v3/xrp/broadcast`, {txData, signatureId})

/**
* For more details, see <a href="https://tatum.io/apidoc#operation/XrpGetLastClosedLedger" target="_blank">Tatum API documentation</a>
Expand All @@ -42,4 +42,4 @@ export const xrpGetTransaction = async (hash: string) => get(`/v3/xrp/transactio
* For more details, see <a href="https://tatum.io/apidoc#operation/XrpGetAccountTx" target="_blank">Tatum API documentation</a>
*/
export const xrpGetAccountTransactions = async (address: string, min?: number, marker?: string) =>
get(`/v3/xrp/account/tx/${address}${min ? `?min=${min}${marker ? `&marker=${marker}` : ''}` : marker ? `?marker=${marker}` : ''}`)
get(`/v3/xrp/account/tx/${address}${min ? `?min=${min}${marker ? `&marker=${marker}` : ''}` : marker ? `?marker=${marker}` : ''}`)
4 changes: 2 additions & 2 deletions src/offchain/xrp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BigNumber from 'bignumber.js'
import {RippleAPI} from 'ripple-lib'
import {xrpGetAccountInfo, xrpGetFee} from '../blockchain'
import { validateBody } from '../connector/tatum'
import {validateBody} from '../connector/tatum'
import {Currency, TransactionKMS, TransferXrpOffchain} from '../model'
import {offchainBroadcast, offchainCancelWithdrawal, offchainStoreWithdrawal} from './common'

Expand Down Expand Up @@ -101,7 +101,7 @@ export const prepareXrpSignedOffchainTransaction =
const prepared = await rippleAPI.preparePayment(account.account_data.Account, payment, {
fee: `${fee}`,
sequence: account.account_data.Sequence,
maxLedgerVersion: account.ledger_current_index + 5,
maxLedgerVersion: (account.ledger_current_index || account.ledger_index) + 500,
})
return (await rippleAPI.sign(prepared.txJSON, secret)).signedTransaction
}
2 changes: 2 additions & 0 deletions src/transaction/xrp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('XRP transactions', () => {
it('should test XRP transaction data', async () => {
jest.spyOn(blockchain, 'xrpGetAccountInfo').mockResolvedValue({
ledger_current_index: 1,
ledger_index: 1,
account_data: {Sequence: 123}
})
const body = new TransferXrp()
Expand All @@ -23,6 +24,7 @@ describe('XRP transactions', () => {
it('should not test XRP transaction data, missing amount', async () => {
jest.spyOn(blockchain, 'xrpGetAccountInfo').mockResolvedValue({
ledger_current_index: 1,
ledger_index: 1,
account_data: {Sequence: 123}
})
const body = new TransferXrp()
Expand Down
2 changes: 1 addition & 1 deletion src/transaction/xrp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const prepareXrpSignedTransaction = async (body: TransferXrp) => {
}
const accountInfo = await xrpGetAccountInfo(fromAccount)
const sequence = accountInfo.account_data.Sequence
const maxLedgerVersion = accountInfo.ledger_current_index + 500
const maxLedgerVersion = (accountInfo.ledger_current_index || accountInfo.ledger_index) + 500
const rippleAPI = new RippleAPI()
const prepared = await rippleAPI.preparePayment(fromAccount, payment, {
fee: f,
Expand Down

0 comments on commit 7fcd19e

Please sign in to comment.