Defines TypeScript types for rippled account method requests & responses (#1498)

* account_channels

* account_currencies

* account_info

* account_lines

* account_objects

* account_offers

* account_tx

* gateway_balances

* no ripple check

* respond to comments

* export methods

* fix typos

* respond to comments

* edit BaseResponse to be more specific
This commit is contained in:
Mayukha Vadari
2021-08-09 14:36:48 -07:00
parent 0886af33fd
commit 68ac32fc06
14 changed files with 402 additions and 2 deletions

View File

@@ -17,4 +17,4 @@ export interface IssuedCurrencyAmount extends IssuedCurrency {
value: string
}
export type Amount = IssuedCurrencyAmount | string
export type Amount = IssuedCurrencyAmount | string

View File

@@ -0,0 +1,38 @@
import { Amount } from ".";
interface CreatedNode {
CreatedNode: {
LedgerEntryType: string
LedgerIndex: string
NewFields: {[field: string]: any}
}
}
interface ModifiedNode {
ModifiedNode: {
LedgerEntryType: string
LedgerIndex: string
FinalFields: {[field: string]: any}
PreviousFields: {[field: string]: any}
PreviousTxnID?: string
PreviouTxnLgrSeq?: number
}
}
interface DeletedNode {
DeletedNode: {
LedgerEntryType: string
LedgerIndex: string
FinalFields: {[field: string]: any}
}
}
type Node = CreatedNode | ModifiedNode | DeletedNode
export interface TransactionMetadata {
AffectedNodes: Node[]
DeliveredAmount?: Amount
delivered_amount?: Amount
TransactionIndex: number
TransactionResult: string
}

View File

@@ -43,4 +43,4 @@ export {
RippleState,
SignerList,
Ticket
}
}

View File

@@ -0,0 +1,39 @@
import { BaseRequest, BaseResponse } from './baseMethod'
import { LedgerIndex } from "../common"
interface Channel {
account: string
amount: string
balance: string
channel_id: string
destination_account: string
settle_delay: number
public_key?: string
public_key_hex?: string
expiration?: number
cancel_after?: number
source_tab?: number
destination_tag?: number
}
export interface AccountChannelsRequest extends BaseRequest {
command: "account_channels"
account: string
destination_account?: string
ledger_hash?: string
ledger_index?: LedgerIndex
limit: number
marker: any
}
export interface AccountChannelsResponse extends BaseResponse {
result: {
account: string
channels: Channel[]
ledger_hash: string
ledger_index: number
validated?: boolean
limit?: number
marker?: any
}
}

View File

@@ -0,0 +1,21 @@
import { BaseRequest, BaseResponse } from './baseMethod'
import { LedgerIndex } from "../common"
export interface AccountCurrenciesRequest extends BaseRequest {
command: "account_currencies"
account: string
destination_account?: string
ledger_hash?: string
ledger_index?: LedgerIndex
strict?: boolean
}
export interface AccountCurrenciesResponse extends BaseResponse {
result: {
ledger_hash?: string
ledger_index: number
receive_currencies: string[]
send_currencies: string[]
validated: boolean
}
}

View File

@@ -0,0 +1,41 @@
import { BaseRequest, BaseResponse } from './baseMethod'
import { LedgerIndex } from "../common"
import { AccountRoot, SignerList } from "../ledger"
export interface AccountInfoRequest extends BaseRequest {
command: "account_info"
account: string
ledger_hash?: string
ledger_index?: LedgerIndex
queue?: boolean
signer_lists?: boolean
strict?: boolean
}
export interface QueueTransaction {
auth_change: boolean
fee: string
fee_level: string
max_spend_drops: string
seq: number
}
export interface QueueData {
txn_count: number
auth_change_queued?: boolean
lowest_sequence?: number
highest_sequence?: number
max_spend_drops_total?: string
transactions?: QueueTransaction[]
}
export interface AccountInfoResponse extends BaseResponse {
result: {
account_data: AccountRoot
signer_lists?: SignerList[]
ledger_current_index?: number
ledger_index?: number
queue_data?: QueueData
validated?: boolean
}
}

View File

@@ -0,0 +1,39 @@
import { BaseRequest, BaseResponse } from './baseMethod'
import { LedgerIndex } from "../common"
interface Trustline {
account: string
balance: string
currency: string
limit: string
limit_peer: string
quality_in: number
quality_out: number
no_ripple?: boolean
no_ripple_peer?: boolean
authorized?: boolean
peer_authorized?: boolean
freeze?: boolean
freeze_peer?: boolean
}
export interface AccountLinesRequest extends BaseRequest {
command: "account_lines"
account: string
ledger_hash?: string
ledger_index?: LedgerIndex
peer?: string
limit?: number
marker?: any
}
export interface AccountLinesResponse extends BaseResponse {
result: {
account: string
lines: Trustline[]
ledger_current_index?: number
ledger_index?: number
ledger_hash?: string
marker?: any
}
}

View File

@@ -0,0 +1,29 @@
import { BaseRequest, BaseResponse } from './baseMethod'
import { AccountObjectType, LedgerIndex } from "../common"
import { Check, DepositPreauth, Escrow, Offer, PayChannel, RippleState, SignerList, Ticket } from "../ledger"
export interface AccountObjectsRequest extends BaseRequest {
command: "account_objects"
account: string
type?: AccountObjectType
deletion_blockers_only?: boolean
ledger_hash?: string
ledger_index?: LedgerIndex
limit?: number
marker?: any
}
type AccountObject = Check | DepositPreauth | Escrow | Offer | PayChannel | SignerList | Ticket | RippleState
export interface AccountObjectsResponse extends BaseResponse {
result: {
account: string
account_objects: AccountObject[]
ledger_hash?: string
ledger_index?: number
ledger_current_index?: number
limit?: number
marker?: string
validated?: boolean
}
}

View File

@@ -0,0 +1,32 @@
import { Amount, LedgerIndex } from "../common";
import { BaseRequest, BaseResponse } from "./baseMethod";
export interface AccountOffersRequest extends BaseRequest {
command: "account_offers"
account: string
ledger_hash?: string
ledger_index?: LedgerIndex
limit?: number
marker?: any
strict?: boolean
}
interface AccountOffer {
flags: number
seq: number
taker_gets: Amount
taker_pays: Amount
quality: string
expiration?: number
}
export interface AccountOffersResponse extends BaseResponse {
result: {
account: string
offers?: AccountOffer[]
ledger_current_index?: number
ledger_index?: number
ledger_hash?: string
marker?: any
}
}

View File

@@ -0,0 +1,36 @@
import { LedgerIndex } from "../common";
import { TransactionMetadata } from "../common/transaction";
import { BaseRequest, BaseResponse } from "./baseMethod";
export interface AccountTxRequest extends BaseRequest {
command: "account_tx"
account: string
ledger_index_min?: number
ledger_index_max?: number
ledger_hash?: string
ledger_index?: LedgerIndex
binary?: boolean
forward?: boolean
limit?: number
marker?: any
}
interface AccountTransaction {
ledger_index: number
meta: string | TransactionMetadata
tx?: any // TODO: replace when transaction objects are done
tx_blob?: string
validated: boolean
}
export interface AccountTxResponse extends BaseResponse {
result: {
account: string
ledger_index_min: number
ledger_index_max: number
limit: number
marker?: any
transactions: AccountTransaction[]
validated?: boolean
}
}

View File

@@ -0,0 +1,26 @@
import { Response } from ".";
export interface BaseRequest {
id: number | string
command: string
api_version?: number
}
interface Warning {
id: number
message: string
details?: {[key: string]: string}
}
export interface BaseResponse {
id: number | string
status: "success" | "error" | string
type: "response" | string
result: any
warning?: "load"
warnings?: Warning[]
forwarded?: boolean
error?: string
request?: Response
api_version?: number
}

View File

@@ -0,0 +1,28 @@
import { LedgerIndex } from '../common'
import { BaseRequest, BaseResponse } from './baseMethod';
export interface GatewayBalancesRequest extends BaseRequest {
command: "gateway_balances"
account: string
strict?: boolean
hotwallet: string | string[]
ledger_hash?: string
ledger_index?: LedgerIndex
}
interface Balance {
currency: string
value: string
}
export interface GatewayBalancesResponse extends BaseResponse {
result: {
account: string
obligations?: {[currency: string]: string}
balances?: {[address: string]: Balance[]}
assets?: {[address: string]: Balance[]}
ledger_hash?: string
ledger_current_index?: number
ledger_index?: number
}
}

View File

@@ -0,0 +1,52 @@
import { AccountChannelsRequest, AccountChannelsResponse } from "./accountChannels";
import { AccountCurrenciesRequest, AccountCurrenciesResponse } from "./accountCurrencies";
import { AccountInfoRequest, AccountInfoResponse } from "./accountInfo";
import { AccountLinesRequest, AccountLinesResponse } from "./accountLines";
import { AccountObjectsRequest, AccountObjectsResponse } from "./accountObjects";
import { AccountOffersRequest, AccountOffersResponse } from "./accountOffers";
import { AccountTxRequest, AccountTxResponse } from "./accountTx";
import { GatewayBalancesRequest, GatewayBalancesResponse } from "./gatewayBalances";
import { NoRippleCheckRequest, NoRippleCheckResponse } from "./norippleCheck";
type Request = AccountChannelsRequest
| AccountCurrenciesRequest
| AccountInfoRequest
| AccountLinesRequest
| AccountObjectsRequest
| AccountOffersRequest
| AccountTxRequest
| GatewayBalancesRequest
| NoRippleCheckRequest
type Response = AccountChannelsResponse
| AccountCurrenciesResponse
| AccountInfoResponse
| AccountLinesResponse
| AccountObjectsResponse
| AccountOffersResponse
| AccountTxResponse
| GatewayBalancesResponse
| NoRippleCheckResponse
export {
Request,
Response,
AccountChannelsRequest,
AccountChannelsResponse,
AccountCurrenciesRequest,
AccountCurrenciesResponse,
AccountInfoRequest,
AccountInfoResponse,
AccountLinesRequest,
AccountLinesResponse,
AccountObjectsRequest,
AccountObjectsResponse,
AccountOffersRequest,
AccountOffersResponse,
AccountTxRequest,
AccountTxResponse,
GatewayBalancesRequest,
GatewayBalancesResponse,
NoRippleCheckRequest,
NoRippleCheckResponse
}

View File

@@ -0,0 +1,19 @@
import { LedgerIndex } from '../common'
import { BaseRequest, BaseResponse } from './baseMethod';
export interface NoRippleCheckRequest extends BaseRequest {
command: "noripple_check"
account: string
role: "gateway" | "user"
transactions?: boolean
ledger_hash?: string
ledger_index?: LedgerIndex
}
export interface NoRippleCheckResponse extends BaseResponse {
result: {
ledger_current_index: number
problems: string[]
transactions: any[] // TODO: fix once transaction objects are implemented
}
}