mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-12 08:35:48 +00:00
Implements TypeScript types for path and order book methods (#1503)
* book offers * deposit authorized * path_find * ripple_path_find * export * fix typos * fix issues * respond to comments * make `pathFind` id optional * make source_currencies optional
This commit is contained in:
@@ -18,3 +18,11 @@ export interface IssuedCurrencyAmount extends IssuedCurrency {
|
||||
}
|
||||
|
||||
export type Amount = IssuedCurrencyAmount | string
|
||||
|
||||
interface PathStep {
|
||||
account?: string
|
||||
currency?: string
|
||||
issuer?: string
|
||||
}
|
||||
|
||||
export type Path = PathStep[]
|
||||
|
||||
34
src/models/methods/bookOffers.ts
Normal file
34
src/models/methods/bookOffers.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Amount, LedgerIndex } from '../common';
|
||||
import { Offer } from '../ledger';
|
||||
import { BaseRequest, BaseResponse } from './baseMethod';
|
||||
|
||||
interface TakerAmount {
|
||||
currency: string
|
||||
issuer?: string
|
||||
}
|
||||
|
||||
export interface BookOffersRequest extends BaseRequest {
|
||||
command: "book_offers"
|
||||
ledger_hash?: string
|
||||
ledger_index?: LedgerIndex
|
||||
limit?: number
|
||||
taker?: string
|
||||
taker_gets: TakerAmount
|
||||
taker_pays: TakerAmount
|
||||
}
|
||||
|
||||
interface BookOffer extends Offer {
|
||||
owner_funds?: string
|
||||
taker_gets_funded?: Amount
|
||||
taker_pays_funded?: Amount
|
||||
quality?: string
|
||||
}
|
||||
|
||||
export interface BookOffersResponse extends BaseResponse {
|
||||
result: {
|
||||
ledger_current_index?: number
|
||||
ledger_index?: number
|
||||
ledger_hash?: string
|
||||
offers: BookOffer[]
|
||||
}
|
||||
}
|
||||
22
src/models/methods/depositAuthorized.ts
Normal file
22
src/models/methods/depositAuthorized.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { LedgerIndex } from '../common';
|
||||
import { BaseRequest, BaseResponse } from './baseMethod';
|
||||
|
||||
export interface DepositAuthorizedRequest extends BaseRequest {
|
||||
command: "deposit_authorized"
|
||||
source_account: string
|
||||
destination_account: string
|
||||
ledger_hash?: string
|
||||
ledger_index?: LedgerIndex
|
||||
}
|
||||
|
||||
export interface DepositAuthorizedResponse extends BaseResponse {
|
||||
result: {
|
||||
deposit_authorized: boolean
|
||||
destination_account: string
|
||||
ledger_hash?: string
|
||||
ledger_index?: number
|
||||
ledger_current_index?: number
|
||||
source_account: string
|
||||
validated?: boolean
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,15 @@ import { AccountLinesRequest, AccountLinesResponse } from "./accountLines";
|
||||
import { AccountObjectsRequest, AccountObjectsResponse } from "./accountObjects";
|
||||
import { AccountOffersRequest, AccountOffersResponse } from "./accountOffers";
|
||||
import { AccountTxRequest, AccountTxResponse } from "./accountTx";
|
||||
import { BookOffersRequest, BookOffersResponse } from "./bookOffers";
|
||||
import { DepositAuthorizedRequest, DepositAuthorizedResponse } from "./depositAuthorized";
|
||||
import { GatewayBalancesRequest, GatewayBalancesResponse } from "./gatewayBalances";
|
||||
import { NoRippleCheckRequest, NoRippleCheckResponse } from "./norippleCheck";
|
||||
import { PathFindRequest, PathFindResponse } from "./pathFind";
|
||||
import { RipplePathFindRequest, RipplePathFindResponse } from "./ripplePathFind";
|
||||
|
||||
type Request = AccountChannelsRequest
|
||||
type Request = // account methods
|
||||
AccountChannelsRequest
|
||||
| AccountCurrenciesRequest
|
||||
| AccountInfoRequest
|
||||
| AccountLinesRequest
|
||||
@@ -17,8 +22,14 @@ type Request = AccountChannelsRequest
|
||||
| AccountTxRequest
|
||||
| GatewayBalancesRequest
|
||||
| NoRippleCheckRequest
|
||||
// path and order book methods
|
||||
| BookOffersRequest
|
||||
| DepositAuthorizedRequest
|
||||
| PathFindRequest
|
||||
| RipplePathFindRequest
|
||||
|
||||
type Response = AccountChannelsResponse
|
||||
type Response = // account methods
|
||||
AccountChannelsResponse
|
||||
| AccountCurrenciesResponse
|
||||
| AccountInfoResponse
|
||||
| AccountLinesResponse
|
||||
@@ -27,10 +38,16 @@ type Response = AccountChannelsResponse
|
||||
| AccountTxResponse
|
||||
| GatewayBalancesResponse
|
||||
| NoRippleCheckResponse
|
||||
// path and order book methods
|
||||
| BookOffersResponse
|
||||
| DepositAuthorizedResponse
|
||||
| PathFindResponse
|
||||
| RipplePathFindResponse
|
||||
|
||||
export {
|
||||
Request,
|
||||
Response,
|
||||
// account methods
|
||||
AccountChannelsRequest,
|
||||
AccountChannelsResponse,
|
||||
AccountCurrenciesRequest,
|
||||
@@ -48,5 +65,14 @@ export {
|
||||
GatewayBalancesRequest,
|
||||
GatewayBalancesResponse,
|
||||
NoRippleCheckRequest,
|
||||
NoRippleCheckResponse
|
||||
NoRippleCheckResponse,
|
||||
// path and order book methods
|
||||
BookOffersRequest,
|
||||
BookOffersResponse,
|
||||
DepositAuthorizedRequest,
|
||||
DepositAuthorizedResponse,
|
||||
PathFindRequest,
|
||||
PathFindResponse,
|
||||
RipplePathFindRequest,
|
||||
RipplePathFindResponse
|
||||
}
|
||||
48
src/models/methods/pathFind.ts
Normal file
48
src/models/methods/pathFind.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Amount, Path } from '../common'
|
||||
import { BaseRequest, BaseResponse } from './baseMethod';
|
||||
|
||||
interface BasePathFindRequest extends BaseRequest {
|
||||
command: "path_find"
|
||||
subcommand: string
|
||||
}
|
||||
|
||||
interface PathFindCreateRequest extends BasePathFindRequest {
|
||||
subcommand: "create"
|
||||
source_account: string
|
||||
destination_account: string
|
||||
destination_amount: Amount
|
||||
send_max?: Amount
|
||||
paths?: Path[]
|
||||
}
|
||||
|
||||
interface PathFindCloseRequest extends BasePathFindRequest {
|
||||
subcommand: "close"
|
||||
}
|
||||
|
||||
interface PathFindStatusRequest extends BasePathFindRequest {
|
||||
subcommand: "status"
|
||||
}
|
||||
|
||||
export type PathFindRequest = PathFindCreateRequest | PathFindCloseRequest | PathFindStatusRequest
|
||||
|
||||
interface PathOption {
|
||||
paths_computed: Path[]
|
||||
source_amount: Amount
|
||||
}
|
||||
|
||||
export interface PathFindResponse extends BaseResponse {
|
||||
result: {
|
||||
alternatives: PathOption[]
|
||||
destination_account: string
|
||||
destination_amount: Amount
|
||||
source_account: string
|
||||
full_reply: boolean
|
||||
id?: number | string
|
||||
closed?: true
|
||||
status?: true
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: figure out where to put the path_find asynchronous follow-ups
|
||||
// https://xrpl.org/path_find.html#asynchronous-follow-ups
|
||||
// probably with the subscribe response objects
|
||||
31
src/models/methods/ripplePathFind.ts
Normal file
31
src/models/methods/ripplePathFind.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Amount, LedgerIndex, Path } from "../common";
|
||||
import { BaseRequest, BaseResponse } from "./baseMethod";
|
||||
|
||||
interface SourceCurrencyAmount {
|
||||
currency: string
|
||||
issuer?: string
|
||||
}
|
||||
|
||||
export interface RipplePathFindRequest extends BaseRequest {
|
||||
command: "ripple_path_find"
|
||||
source_account: string
|
||||
destination_account: string
|
||||
destination_amount: Amount
|
||||
send_max?: Amount
|
||||
source_currencies?: SourceCurrencyAmount
|
||||
ledger_hash?: string
|
||||
ledger_index?: LedgerIndex
|
||||
}
|
||||
|
||||
interface PathOption {
|
||||
paths_computed: Path[]
|
||||
source_amount: Amount
|
||||
}
|
||||
|
||||
export interface RipplePathFindResponse extends BaseResponse {
|
||||
result: {
|
||||
alternatives: PathOption[]
|
||||
destination_account: string
|
||||
destination_currencies: string[]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user