mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-02 10:05:49 +00:00
Types cleanup + more API methods onto new request method (#857)
* major types cleanup, more formatted api methods onto new request method - getPaymentChannel() now uses this.request() - getSettings() now uses this.request() - getLedger() now uses this.request() - transaction types cleaned up a bit, but still some work left to do
This commit is contained in:
committed by
Elliot Lee
parent
c175e3f58e
commit
187154a2b0
@@ -3,12 +3,22 @@ import * as utils from './utils'
|
||||
import parseTransaction from './parse/transaction'
|
||||
import {validate, errors} from '../common'
|
||||
import {Connection} from '../common'
|
||||
import {
|
||||
TransactionType, TransactionResponse, TransactionOptions
|
||||
} from './transaction-types'
|
||||
import {FormattedTransactionType} from '../transaction/types'
|
||||
|
||||
export type TransactionOptions = {
|
||||
minLedgerVersion?: number,
|
||||
maxLedgerVersion?: number
|
||||
}
|
||||
type TransactionResponse = FormattedTransactionType & {
|
||||
hash: string,
|
||||
ledger_index: number,
|
||||
meta: any,
|
||||
validated?: boolean
|
||||
}
|
||||
|
||||
|
||||
function attachTransactionDate(connection: Connection, tx: any
|
||||
): Promise<TransactionType> {
|
||||
): Promise<FormattedTransactionType> {
|
||||
if (tx.date) {
|
||||
return Promise.resolve(tx)
|
||||
}
|
||||
@@ -71,7 +81,7 @@ function convertError(connection: Connection, options: TransactionOptions,
|
||||
}
|
||||
|
||||
function formatResponse(options: TransactionOptions, tx: TransactionResponse
|
||||
): TransactionType {
|
||||
): FormattedTransactionType {
|
||||
if (tx.validated !== true || !isTransactionInRange(tx, options)) {
|
||||
throw new errors.NotFoundError('Transaction not found')
|
||||
}
|
||||
@@ -79,7 +89,7 @@ function formatResponse(options: TransactionOptions, tx: TransactionResponse
|
||||
}
|
||||
|
||||
function getTransaction(id: string, options: TransactionOptions = {}
|
||||
): Promise<TransactionType> {
|
||||
): Promise<FormattedTransactionType> {
|
||||
validate.getTransaction({id, options})
|
||||
|
||||
const request = {
|
||||
|
||||
Reference in New Issue
Block a user