From 68ac32fc060c34b42da4d9a80e18e21cebbb777c Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Mon, 9 Aug 2021 14:36:48 -0700 Subject: [PATCH] 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 --- src/models/common/index.ts | 2 +- src/models/common/transaction.ts | 38 ++++++++++++++++++ src/models/ledger/index.ts | 2 +- src/models/methods/accountChannels.ts | 39 +++++++++++++++++++ src/models/methods/accountCurrencies.ts | 21 ++++++++++ src/models/methods/accountInfo.ts | 41 +++++++++++++++++++ src/models/methods/accountLines.ts | 39 +++++++++++++++++++ src/models/methods/accountObjects.ts | 29 ++++++++++++++ src/models/methods/accountOffers.ts | 32 +++++++++++++++ src/models/methods/accountTx.ts | 36 +++++++++++++++++ src/models/methods/baseMethod.ts | 26 +++++++++++++ src/models/methods/gatewayBalances.ts | 28 +++++++++++++ src/models/methods/index.ts | 52 +++++++++++++++++++++++++ src/models/methods/norippleCheck.ts | 19 +++++++++ 14 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 src/models/common/transaction.ts create mode 100644 src/models/methods/accountChannels.ts create mode 100644 src/models/methods/accountCurrencies.ts create mode 100644 src/models/methods/accountInfo.ts create mode 100644 src/models/methods/accountLines.ts create mode 100644 src/models/methods/accountObjects.ts create mode 100644 src/models/methods/accountOffers.ts create mode 100644 src/models/methods/accountTx.ts create mode 100644 src/models/methods/baseMethod.ts create mode 100644 src/models/methods/gatewayBalances.ts create mode 100644 src/models/methods/index.ts create mode 100644 src/models/methods/norippleCheck.ts diff --git a/src/models/common/index.ts b/src/models/common/index.ts index 66ad1f33..27fef92e 100644 --- a/src/models/common/index.ts +++ b/src/models/common/index.ts @@ -17,4 +17,4 @@ export interface IssuedCurrencyAmount extends IssuedCurrency { value: string } -export type Amount = IssuedCurrencyAmount | string \ No newline at end of file +export type Amount = IssuedCurrencyAmount | string diff --git a/src/models/common/transaction.ts b/src/models/common/transaction.ts new file mode 100644 index 00000000..69e2550d --- /dev/null +++ b/src/models/common/transaction.ts @@ -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 +} \ No newline at end of file diff --git a/src/models/ledger/index.ts b/src/models/ledger/index.ts index 4301f42b..4be46fa2 100644 --- a/src/models/ledger/index.ts +++ b/src/models/ledger/index.ts @@ -43,4 +43,4 @@ export { RippleState, SignerList, Ticket -} \ No newline at end of file +} diff --git a/src/models/methods/accountChannels.ts b/src/models/methods/accountChannels.ts new file mode 100644 index 00000000..2a96589e --- /dev/null +++ b/src/models/methods/accountChannels.ts @@ -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 + } +} diff --git a/src/models/methods/accountCurrencies.ts b/src/models/methods/accountCurrencies.ts new file mode 100644 index 00000000..1151cad4 --- /dev/null +++ b/src/models/methods/accountCurrencies.ts @@ -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 + } +} diff --git a/src/models/methods/accountInfo.ts b/src/models/methods/accountInfo.ts new file mode 100644 index 00000000..188bb2c0 --- /dev/null +++ b/src/models/methods/accountInfo.ts @@ -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 + } +} \ No newline at end of file diff --git a/src/models/methods/accountLines.ts b/src/models/methods/accountLines.ts new file mode 100644 index 00000000..2b15614f --- /dev/null +++ b/src/models/methods/accountLines.ts @@ -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 + } +} diff --git a/src/models/methods/accountObjects.ts b/src/models/methods/accountObjects.ts new file mode 100644 index 00000000..80eb546b --- /dev/null +++ b/src/models/methods/accountObjects.ts @@ -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 + } +} \ No newline at end of file diff --git a/src/models/methods/accountOffers.ts b/src/models/methods/accountOffers.ts new file mode 100644 index 00000000..2e89be37 --- /dev/null +++ b/src/models/methods/accountOffers.ts @@ -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 + } +} diff --git a/src/models/methods/accountTx.ts b/src/models/methods/accountTx.ts new file mode 100644 index 00000000..c05798fb --- /dev/null +++ b/src/models/methods/accountTx.ts @@ -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 + } +} diff --git a/src/models/methods/baseMethod.ts b/src/models/methods/baseMethod.ts new file mode 100644 index 00000000..917625dc --- /dev/null +++ b/src/models/methods/baseMethod.ts @@ -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 +} \ No newline at end of file diff --git a/src/models/methods/gatewayBalances.ts b/src/models/methods/gatewayBalances.ts new file mode 100644 index 00000000..b9da2d2d --- /dev/null +++ b/src/models/methods/gatewayBalances.ts @@ -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 + } +} diff --git a/src/models/methods/index.ts b/src/models/methods/index.ts new file mode 100644 index 00000000..4914713d --- /dev/null +++ b/src/models/methods/index.ts @@ -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 +} \ No newline at end of file diff --git a/src/models/methods/norippleCheck.ts b/src/models/methods/norippleCheck.ts new file mode 100644 index 00000000..75d28cee --- /dev/null +++ b/src/models/methods/norippleCheck.ts @@ -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 + } +}