mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
Add new request interface, implement first few request typings (#843)
* Add request interface & typings - src/api: add basic implementation of request/requestAll() - src/ledgers/account_info: refactor to simplify with request() - src/ledgers/balances: refactor to simplify with request() - src/ledgers/orderbook: refactor to simplify with requestAll() - src/ledgers/orders: refactor to simplify with requestAll() - src/ledgers/trustlines: refactor to simplify with requestAll() * standardize on Formatted prefix
This commit is contained in:
committed by
Elliot Lee
parent
4a21360e37
commit
365de6d18a
@@ -1,31 +1,12 @@
|
||||
import {validate, removeUndefined, dropsToXrp} from '../common'
|
||||
import {RippleAPI} from '../api'
|
||||
import {AccountInfoResponse} from '../common/types/commands/account_info'
|
||||
|
||||
type AccountData = {
|
||||
Sequence: number,
|
||||
Account: string,
|
||||
Balance: string,
|
||||
Flags: number,
|
||||
LedgerEntryType: string,
|
||||
OwnerCount: number,
|
||||
PreviousTxnID: string,
|
||||
AccountTxnID?: string,
|
||||
PreviousTxnLgrSeq: number,
|
||||
index: string
|
||||
}
|
||||
|
||||
type AccountDataResponse = {
|
||||
account_data: AccountData,
|
||||
ledger_current_index?: number,
|
||||
ledger_hash?: string,
|
||||
ledger_index: number,
|
||||
validated: boolean
|
||||
}
|
||||
|
||||
type AccountInfoOptions = {
|
||||
type GetAccountInfoOptions = {
|
||||
ledgerVersion?: number
|
||||
}
|
||||
|
||||
type AccountInfoResponse = {
|
||||
type FormattedGetAccountInfoResponse = {
|
||||
sequence: number,
|
||||
xrpBalance: string,
|
||||
ownerCount: number,
|
||||
@@ -34,7 +15,9 @@ type AccountInfoResponse = {
|
||||
previousAffectingTransactionLedgerVersion: number
|
||||
}
|
||||
|
||||
function formatAccountInfo(response: AccountDataResponse) {
|
||||
function formatAccountInfo(
|
||||
response: AccountInfoResponse
|
||||
): FormattedGetAccountInfoResponse {
|
||||
const data = response.account_data
|
||||
return removeUndefined({
|
||||
sequence: data.Sequence,
|
||||
@@ -46,17 +29,16 @@ function formatAccountInfo(response: AccountDataResponse) {
|
||||
})
|
||||
}
|
||||
|
||||
function getAccountInfo(address: string, options: AccountInfoOptions = {}
|
||||
): Promise<AccountInfoResponse> {
|
||||
export default async function getAccountInfo(
|
||||
this: RippleAPI, address: string, options: GetAccountInfoOptions = {}
|
||||
): Promise<FormattedGetAccountInfoResponse> {
|
||||
// 1. Validate
|
||||
validate.getAccountInfo({address, options})
|
||||
|
||||
const request = {
|
||||
command: 'account_info',
|
||||
// 2. Make Request
|
||||
const response = await this._request('account_info', {
|
||||
account: address,
|
||||
ledger_index: options.ledgerVersion || 'validated'
|
||||
}
|
||||
|
||||
return this.connection.request(request).then(formatAccountInfo)
|
||||
})
|
||||
// 3. Return Formatted Response
|
||||
return formatAccountInfo(response)
|
||||
}
|
||||
|
||||
export default getAccountInfo
|
||||
|
||||
Reference in New Issue
Block a user