mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 03:35:49 +00:00
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import {
|
|
validate,
|
|
removeUndefined,
|
|
dropsToXrp,
|
|
ensureClassicAddress
|
|
} from '../common'
|
|
import {RippleAPI} from '..'
|
|
import {AccountInfoResponse} from '../common/types/commands/account_info'
|
|
|
|
export type GetAccountInfoOptions = {
|
|
ledgerVersion?: number
|
|
}
|
|
|
|
export type FormattedGetAccountInfoResponse = {
|
|
sequence: number
|
|
xrpBalance: string
|
|
ownerCount: number
|
|
previousInitiatedTransactionID: string
|
|
previousAffectingTransactionID: string
|
|
previousAffectingTransactionLedgerVersion: number
|
|
}
|
|
|
|
function formatAccountInfo(
|
|
response: AccountInfoResponse
|
|
): FormattedGetAccountInfoResponse {
|
|
const data = response.account_data
|
|
return removeUndefined({
|
|
sequence: data.Sequence,
|
|
xrpBalance: dropsToXrp(data.Balance),
|
|
ownerCount: data.OwnerCount,
|
|
previousInitiatedTransactionID: data.AccountTxnID,
|
|
previousAffectingTransactionID: data.PreviousTxnID,
|
|
previousAffectingTransactionLedgerVersion: data.PreviousTxnLgrSeq
|
|
})
|
|
}
|
|
|
|
export default async function getAccountInfo(
|
|
this: RippleAPI,
|
|
address: string,
|
|
options: GetAccountInfoOptions = {}
|
|
): Promise<FormattedGetAccountInfoResponse> {
|
|
// 1. Validate
|
|
validate.getAccountInfo({address, options})
|
|
|
|
// Only support retrieving account info without a tag,
|
|
// since account info is not distinguished by tag.
|
|
address = ensureClassicAddress(address)
|
|
|
|
// 2. Make Request
|
|
const response = await this.request('account_info', {
|
|
account: address,
|
|
ledger_index: options.ledgerVersion || 'validated'
|
|
})
|
|
// 3. Return Formatted Response
|
|
return formatAccountInfo(response)
|
|
}
|