Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 32 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/models/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export interface IssuedCurrencyAmount extends IssuedCurrency {
value: string
}

export type Amount = IssuedCurrencyAmount | string
export type Amount = IssuedCurrencyAmount | string
38 changes: 38 additions & 0 deletions src/models/common/transaction.ts
Original file line number Diff line number Diff line change
@@ -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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we can narrow this from {[field: string]: any? Does this come in the form of a LedgerEntry that we can use to replace any here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could in theory narrow it, but as far as I understand, it's a subset of LedgerEntry fields, and isn't necessarily a full LedgerEntry object. I suppose this is another question for @intelliot

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably any (modifiable) fields in any ledger object, so I believe there are a lot of possibilities, and it'll expand in the future as more kinds of ledger objects are added in the future. I would fine with leaving this as-is, but of course, if we want to make this more specific in the future, that would be fine as well.

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
}
2 changes: 1 addition & 1 deletion src/models/ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ export {
RippleState,
SignerList,
Ticket
}
}
39 changes: 39 additions & 0 deletions src/models/methods/accountChannels.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
21 changes: 21 additions & 0 deletions src/models/methods/accountCurrencies.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
41 changes: 41 additions & 0 deletions src/models/methods/accountInfo.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
39 changes: 39 additions & 0 deletions src/models/methods/accountLines.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
29 changes: 29 additions & 0 deletions src/models/methods/accountObjects.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
32 changes: 32 additions & 0 deletions src/models/methods/accountOffers.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
36 changes: 36 additions & 0 deletions src/models/methods/accountTx.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
26 changes: 26 additions & 0 deletions src/models/methods/baseMethod.ts
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions src/models/methods/gatewayBalances.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading