mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Implements TypeScript types for subscribe requests/responses/streams (#1510)
* subscribe * streams * unsubscribe * exports * fix merge issues * respond to comments
This commit is contained in:
@@ -19,6 +19,8 @@ export interface IssuedCurrencyAmount extends IssuedCurrency {
|
||||
|
||||
export type Amount = IssuedCurrencyAmount | string
|
||||
|
||||
export type StreamType = "consensus" | "ledger" | "manifests" | "peer_status" | "transactions" | "transactions_proposed" | "server" | "validations"
|
||||
|
||||
interface PathStep {
|
||||
account?: string
|
||||
currency?: string
|
||||
|
||||
@@ -9,6 +9,8 @@ import { BookOffersRequest, BookOffersResponse } from "./bookOffers";
|
||||
import { DepositAuthorizedRequest, DepositAuthorizedResponse } from "./depositAuthorized";
|
||||
import { GatewayBalancesRequest, GatewayBalancesResponse } from "./gatewayBalances";
|
||||
import { NoRippleCheckRequest, NoRippleCheckResponse } from "./norippleCheck";
|
||||
import { ConsensusStream, LedgerStream, OrderBookStream, PeerStatusStream, Stream, SubscribeRequest, SubscribeResponse, TransactionStream, ValidationStream } from "./subscribe";
|
||||
import { UnsubscribeRequest, UnsubscribeResponse } from "./unsubscribe";
|
||||
import { PathFindRequest, PathFindResponse } from "./pathFind";
|
||||
import { RipplePathFindRequest, RipplePathFindResponse } from "./ripplePathFind";
|
||||
|
||||
@@ -27,6 +29,9 @@ type Request = // account methods
|
||||
| DepositAuthorizedRequest
|
||||
| PathFindRequest
|
||||
| RipplePathFindRequest
|
||||
// subscription methods
|
||||
| SubscribeRequest
|
||||
| UnsubscribeRequest
|
||||
|
||||
type Response = // account methods
|
||||
AccountChannelsResponse
|
||||
@@ -43,6 +48,9 @@ type Response = // account methods
|
||||
| DepositAuthorizedResponse
|
||||
| PathFindResponse
|
||||
| RipplePathFindResponse
|
||||
// subscription methods
|
||||
| SubscribeResponse
|
||||
| UnsubscribeResponse
|
||||
|
||||
export {
|
||||
Request,
|
||||
@@ -74,5 +82,17 @@ export {
|
||||
PathFindRequest,
|
||||
PathFindResponse,
|
||||
RipplePathFindRequest,
|
||||
RipplePathFindResponse
|
||||
}
|
||||
RipplePathFindResponse,
|
||||
// Subscribe methods/streams
|
||||
SubscribeRequest,
|
||||
SubscribeResponse,
|
||||
Stream,
|
||||
LedgerStream,
|
||||
ValidationStream,
|
||||
TransactionStream,
|
||||
PeerStatusStream,
|
||||
OrderBookStream,
|
||||
ConsensusStream,
|
||||
UnsubscribeRequest,
|
||||
UnsubscribeResponse
|
||||
}
|
||||
|
||||
107
src/models/methods/subscribe.ts
Normal file
107
src/models/methods/subscribe.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { BaseRequest, BaseResponse } from './baseMethod'
|
||||
import { Currency, StreamType } from "../common"
|
||||
import { TransactionMetadata } from '../common/transaction'
|
||||
|
||||
interface Book {
|
||||
taker_gets: Currency
|
||||
taker_pays: Currency
|
||||
taker: string
|
||||
snapshot?: boolean
|
||||
both?: boolean
|
||||
}
|
||||
|
||||
export interface SubscribeRequest extends BaseRequest {
|
||||
command: "subscribe"
|
||||
streams?: StreamType[]
|
||||
accounts?: string[]
|
||||
accounts_proposed?: string[]
|
||||
books?: Book[]
|
||||
url?: string
|
||||
url_username?: string
|
||||
url_password?: string
|
||||
}
|
||||
|
||||
export interface SubscribeResponse extends BaseResponse {
|
||||
result: any
|
||||
}
|
||||
|
||||
interface BaseStream {
|
||||
type: string
|
||||
}
|
||||
|
||||
export interface LedgerStream extends BaseStream {
|
||||
type: "ledgerClosed"
|
||||
fee_base: number
|
||||
fee_ref: number
|
||||
ledger_hash: string
|
||||
ledger_index: number
|
||||
ledger_time: number
|
||||
reserve_base: number
|
||||
reserve_inc: number
|
||||
txn_count: number
|
||||
validated_ledgers?: string
|
||||
}
|
||||
|
||||
export interface ValidationStream extends BaseStream {
|
||||
type: "validationReceived"
|
||||
amendments?: string[]
|
||||
base_fee?: number
|
||||
flags: number
|
||||
full: boolean
|
||||
ledger_hash: string
|
||||
ledger_index: string
|
||||
load_fee?: number
|
||||
master_key?: string
|
||||
reserve_base?: number
|
||||
reserve_inc?: number
|
||||
signature: string
|
||||
signing_time: number
|
||||
validation_public_key: string
|
||||
}
|
||||
|
||||
export interface TransactionStream extends BaseStream {
|
||||
status: string
|
||||
type: "transaction"
|
||||
engine_result: string
|
||||
engine_result_code: number
|
||||
engine_result_message: string
|
||||
ledger_current_index?: number
|
||||
ledger_hash?: string
|
||||
ledger_index?: number
|
||||
meta?: TransactionMetadata
|
||||
transaction: any // TODO: replace when we have types for transactions
|
||||
validated?: boolean
|
||||
}
|
||||
|
||||
export interface PeerStatusStream extends BaseStream {
|
||||
type: "peerStatusChange"
|
||||
action: "CLOSING_LEDGER" | "ACCEPTED_LEDGER" | "SWITCHED_LEDGER" | "LOST_SYNC"
|
||||
date: number
|
||||
ledger_hash?: string
|
||||
ledger_index?: number
|
||||
ledger_index_max?: number
|
||||
ledger_index_min?: number
|
||||
}
|
||||
|
||||
export interface OrderBookStream extends BaseStream {
|
||||
status: string
|
||||
type: "transaction"
|
||||
engine_result: string
|
||||
engine_result_code: number
|
||||
engine_result_message: string
|
||||
ledger_current_index?: number
|
||||
ledger_hash?: string
|
||||
ledger_index?: number
|
||||
meta: TransactionMetadata
|
||||
transaction: any // TODO: replace when we have types for transactions
|
||||
// TODO: transactions for this object have a special case for OfferCreate
|
||||
// https://xrpl.org/subscribe.html#order-book-streams
|
||||
validated: boolean
|
||||
}
|
||||
|
||||
export interface ConsensusStream extends BaseStream {
|
||||
type: "consensusPhase"
|
||||
consensus: "open" | "establish" | "accepted"
|
||||
}
|
||||
|
||||
export type Stream = LedgerStream | ValidationStream | TransactionStream | PeerStatusStream | OrderBookStream | ConsensusStream
|
||||
20
src/models/methods/unsubscribe.ts
Normal file
20
src/models/methods/unsubscribe.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Currency, StreamType } from "../common";
|
||||
import { BaseRequest, BaseResponse } from "./baseMethod";
|
||||
|
||||
interface Book {
|
||||
taker_gets: Currency
|
||||
taker_pays: Currency
|
||||
both?: boolean
|
||||
}
|
||||
|
||||
export interface UnsubscribeRequest extends BaseRequest {
|
||||
command: "unsubscribe"
|
||||
streams?: StreamType[]
|
||||
accounts?: string[]
|
||||
accounts_proposed?: string[]
|
||||
books?: Book[]
|
||||
}
|
||||
|
||||
export interface UnsubscribeResponse extends BaseResponse {
|
||||
result: {}
|
||||
}
|
||||
Reference in New Issue
Block a user