Added Ledger Method Interfaces (#1502)

Added request and response method interfaces for the api.
This commit is contained in:
Jackson Mills
2021-08-11 09:17:37 -07:00
committed by Mayukha Vadari
parent 2166d8349e
commit ec54841617
6 changed files with 198 additions and 0 deletions

View File

@@ -17,6 +17,11 @@ import { PathFindRequest, PathFindResponse } from "./pathFind";
import { PingRequest, PingResponse } from "./ping";
import { RandomRequest, RandomResponse } from "./random";
import { RipplePathFindRequest, RipplePathFindResponse } from "./ripplePathFind";
import { LedgerRequest, LedgerResponse } from "./ledger";
import { LedgerClosedRequest, LedgerClosedResponse } from "./ledgerClosed";
import { LedgerDataRequest, LedgerDataResponse } from "./ledgerData";
import { LedgerEntryRequest, LedgerEntryResponse } from "./ledgerEntry";
import { LedgerCurrentRequest, LedgerCurrentResponse } from "./ledgerCurrent";
import { ServerInfoRequest, ServerInfoResponse } from "./serverInfo";
import { ServerStateRequest, ServerStateResponse } from "./serverState";
import { SubmitRequest, SubmitResponse } from "./submit";
@@ -34,6 +39,12 @@ type Request = // account methods
| AccountTxRequest
| GatewayBalancesRequest
| NoRippleCheckRequest
// ledger methods
| LedgerRequest
| LedgerClosedRequest
| LedgerCurrentRequest
| LedgerDataRequest
| LedgerEntryRequest
// transaction methods
| SubmitRequest
| SubmitMultisignedRequest
@@ -56,6 +67,7 @@ type Request = // account methods
| PingRequest
| RandomRequest
type Response = // account methods
AccountChannelsResponse
| AccountCurrenciesResponse
@@ -66,6 +78,12 @@ type Response = // account methods
| AccountTxResponse
| GatewayBalancesResponse
| NoRippleCheckResponse
// ledger methods
| LedgerResponse
| LedgerClosedResponse
| LedgerCurrentResponse
| LedgerDataResponse
| LedgerEntryResponse
// transaction methods
| SubmitResponse
| SubmitMultisignedResponse
@@ -88,6 +106,7 @@ type Response = // account methods
| PingResponse
| RandomResponse
export {
Request,
Response,
@@ -110,6 +129,17 @@ export {
GatewayBalancesResponse,
NoRippleCheckRequest,
NoRippleCheckResponse,
// ledger methods
LedgerRequest,
LedgerResponse,
LedgerClosedRequest,
LedgerClosedResponse,
LedgerCurrentRequest,
LedgerCurrentResponse,
LedgerDataRequest,
LedgerDataResponse,
LedgerEntryRequest,
LedgerEntryResponse,
// transaction methods
SubmitRequest,
SubmitResponse,

View File

@@ -0,0 +1,58 @@
import { LedgerIndex } from "../common";
import { LedgerEntry } from "../ledger";
import { BaseRequest, BaseResponse } from "./baseMethod";
export interface LedgerRequest extends BaseRequest {
command: "ledger"
ledger_hash?: string,
ledger_index?: LedgerIndex
full?: boolean
accounts?: boolean
transactions?: boolean
expand?: boolean
owner_funds?: boolean
binary?: boolean
queue?: boolean
}
interface Ledger {
account_hash: string
accountState?: LedgerEntry[]
close_flags: number
close_time: number
close_time_human: string
close_time_resolution: number
closed: boolean
ledger_hash: string
ledger_index: string
parent_close_time: number
parent_hash: string
total_coins: string
transaction_hash: string
transactions?: any[] // TODO: Retype this once we have transaction types
}
interface LedgerQueueData {
account: string
// TODO: Retype tx once we have transaction types
// Also include tx_blob as possible type: https://xrpl.org/ledger.html
// Also handle the special case where 'owner_funds: string' is a field of OfferCreate sometimes - https://xrpl.org/ledger.html#response-format
tx: any
retries_remaining: number
preflight_result: string
last_result?: string
auth_change?: boolean
fee?: string
fee_level?: string
max_spend_drops?: string
}
export interface LedgerResponse extends BaseResponse {
result: {
ledger: Ledger
ledger_hash: string
ledger_index: number
queue_data?: (LedgerQueueData | string)[]
validated: boolean //TODO: Figure out if the example is correct, or the documentation for this field - https://xrpl.org/ledger.html#response-format
}
}

View File

@@ -0,0 +1,12 @@
import { BaseRequest, BaseResponse } from "./baseMethod";
export interface LedgerClosedRequest extends BaseRequest {
command: "ledger_closed"
}
export interface LedgerClosedResponse extends BaseResponse {
result: {
ledger_hash: string
ledger_index: number
}
}

View File

@@ -0,0 +1,11 @@
import { BaseRequest, BaseResponse } from "./baseMethod";
export interface LedgerCurrentRequest extends BaseRequest {
command: "ledger_current"
}
export interface LedgerCurrentResponse extends BaseResponse {
result: {
ledger_current_index: number
}
}

View File

@@ -0,0 +1,27 @@
import { LedgerIndex } from "../common";
import { LedgerEntry } from "../ledger";
import { BaseRequest, BaseResponse } from "./baseMethod";
export interface LedgerDataRequest extends BaseRequest {
command: "ledger_data"
ledger_hash?: string
ledger_index?: LedgerIndex
binary?: boolean
limit?: number
marker?: any
}
type LabeledLedgerEntry = ({ledgerEntryType: string} & LedgerEntry)
type BinaryLedgerEntry = {data: string}
type State = {index: string} & (BinaryLedgerEntry | LabeledLedgerEntry)
export interface LedgerDataResponse extends BaseResponse {
result: {
ledger_index: number
ledger_hash: string
state: State[]
marker?: any
}
}

View File

@@ -0,0 +1,60 @@
import { BaseRequest, BaseResponse } from "./baseMethod";
import { LedgerEntry } from "../ledger";
import { LedgerIndex } from "../common";
export interface LedgerEntryRequest extends BaseRequest {
binary?: boolean
ledger_hash?: string
ledger_index?: LedgerIndex
// Only one of the following properties should be defined in a single request
// https://xrpl.org/ledger_entry.html
index?: string
account_root?: string
directory?: {
sub_index?: number
dir_root?: string
owner?: string
} | string
offer?: {
account: string
seq: number
} | string
ripple_state?: {
accounts: string[]
currency: string
}
check?: string
escrow?: {
owner: string
seq: number
} | string
payment_channel?: string
deposit_preauth?: {
owner: string
authorized: string
} | string
ticket?: {
owner: string
ticket_sequence: number
} | string
}
export interface LedgerEntryResponse extends BaseResponse {
result: {
index: string
ledger_index: number
node?: LedgerEntry
node_binary?: string
}
}