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

Existing types cleanup + more api methods onto new request method #857

Merged
merged 3 commits into from
Mar 14, 2018
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
8 changes: 7 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ import {
AccountInfoRequest, AccountInfoResponse,
AccountLinesRequest, AccountLinesResponse,
BookOffersRequest, BookOffersResponse,
GatewayBalancesRequest, GatewayBalancesResponse
GatewayBalancesRequest, GatewayBalancesResponse,
LedgerRequest, LedgerResponse,
LedgerEntryRequest, LedgerEntryResponse
} from './common/types/commands'


Expand Down Expand Up @@ -154,6 +156,10 @@ class RippleAPI extends EventEmitter {
Promise<BookOffersResponse>
async _request(command: 'gateway_balances', params: GatewayBalancesRequest):
Promise<GatewayBalancesResponse>
async _request(command: 'ledger', params: LedgerRequest):
Promise<LedgerResponse>
async _request(command: 'ledger_entry', params: LedgerEntryRequest):
Promise<LedgerEntryResponse>
async _request(command: string, params: any = {}) {
return this.connection.request({
...params,
Expand Down
27 changes: 7 additions & 20 deletions src/common/types/commands/account_info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {AccountRoot, SignerList} from '../objects'
import {
AccountRootLedgerEntry,
SignerListLedgerEntry,
QueueData
} from '../objects'

export interface AccountInfoRequest {
account: string,
Expand All @@ -10,27 +14,10 @@ export interface AccountInfoRequest {
}

export interface AccountInfoResponse {
account_data: AccountRoot,
signer_lists?: SignerList[],
account_data: AccountRootLedgerEntry,
signer_lists?: SignerListLedgerEntry[],
ledger_current_index?: number,
ledger_index?: number,
queue_data?: QueueData,
validated?: boolean
}

export interface QueueData {
txn_count: number,
auth_change_queued?: boolean,
lowest_sequence?: number,
highest_sequence?: number,
max_spend_drops_total?: string,
transactions?: TransactionData[]
}

export interface TransactionData {
auth_change?: boolean,
fee?: string,
fee_level?: string,
max_spend_drops?: string,
seq?: number
}
10 changes: 5 additions & 5 deletions src/common/types/commands/book_offers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
TakerRequestAmount,
OfferCreateTransaction,
RippledAmount
RippledAmount,
OfferCreateTransaction
} from '../objects'

export interface BookOffersRequest {
Expand All @@ -15,15 +15,15 @@ export interface BookOffersRequest {
}

export interface BookOffersResponse {
offers: OrderBookOffer[],
offers: BookOffer[],
ledger_hash?: string,
ledger_current_index?: number,
ledger_index?: number,
marker?: any
}

export interface OrderBookOffer extends OfferCreateTransaction {
quality?: number
export interface BookOffer extends OfferCreateTransaction {
quality?: string
owner_funds?: string,
taker_gets_funded?: RippledAmount,
taker_pays_funded?: RippledAmount
Expand Down
1 change: 0 additions & 1 deletion src/common/types/commands/gateway_balances.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Amount} from '../objects'


export interface GatewayBalancesRequest {
account: string,
strict?: boolean,
Expand Down
2 changes: 2 additions & 0 deletions src/common/types/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export * from './account_lines'
export * from './account_offers'
export * from './book_offers'
export * from './gateway_balances'
export * from './ledger'
export * from './ledger_entry'
20 changes: 20 additions & 0 deletions src/common/types/commands/ledger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Ledger, QueueData} from '../objects'

export interface LedgerRequest {
ledger_hash?: string
ledger_index?: number | ('validated' | 'closed' | 'current')
full?: boolean
accounts?: boolean
transactions?: boolean
expand?: boolean
owner_funds?: boolean
binary?: boolean
queue?: boolean
}

export interface LedgerResponse {
ledger_index: number
ledger_hash: string
ledger: Ledger
queue_data?: QueueData
}
31 changes: 31 additions & 0 deletions src/common/types/commands/ledger_entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {LedgerEntry} from '../objects'

export interface LedgerEntryRequest {
ledger_hash?: string
ledger_index?: number | ('validated' | 'closed' | 'current')
index?: string,
account_root?: string,
directory?: string | {
sub_index?: number,
dir_root: string
} | {
sub_index?: number,
owner: string
},
offer?: string | {
account: string,
seq: number
},
ripple_state?: {
accounts: [string, string],
currency: string
},
binary?: boolean
}

export interface LedgerEntryResponse {
index: string,
ledger_index: number,
node_binary?: string,
node?: LedgerEntry,
}
17 changes: 0 additions & 17 deletions src/common/types/objects/accounts.ts

This file was deleted.

6 changes: 5 additions & 1 deletion src/common/types/objects/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export * from './accounts'
export * from './adjustments'
export * from './amounts'
export * from './ledger'
export * from './ledger_entries'
export * from './memos'
export * from './orders'
export * from './queue_data'
export * from './settings'
export * from './signers'
export * from './transactions'
export * from './trustlines'
26 changes: 26 additions & 0 deletions src/common/types/objects/ledger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export interface Ledger {
account_hash: string,
accounts?: any[],
close_time: number,
close_time_human: string,
close_time_resolution: number,
closed: boolean,
ledger_hash: string,
ledger_index: string,
parent_hash: string,
total_coins: string,
transaction_hash: string,
transactions: string[] | object[],
// @deprecated
seqNum?: string,
// @deprecated
totalCoins?: string,
// @deprecated
hash?: string,
// TODO: undocumented
close_flags?: number,
// TODO: undocumented
parent_close_time?: number,
// TODO: undocumented
accountState?: any
}
56 changes: 56 additions & 0 deletions src/common/types/objects/ledger_entries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {SignerEntry} from './index'

export interface PayChannelLedgerEntry {
LedgerEntryType: 'PayChannel',
Sequence: number,
Account: string,
Amount: string,
Balance: string,
PublicKey: string,
Destination: string,
SettleDelay: number,
Expiration?: number,
CancelAfter?: number,
SourceTag?: number,
DestinationTag?: number,
OwnerNode: string,
PreviousTxnID: string,
PreviousTxnLgrSeq: number,
index: string
}

export interface AccountRootLedgerEntry {
LedgerEntryType: 'AccountRoot',
Account: string,
Flags: number,
Sequence: number,
Balance: string,
OwnerCount: number,
PreviousTxnID: string,
PreviousTxnLgrSeq: number,
AccountTxnID?: string,
RegularKey?: string,
EmailHash?: string,
MessageKey?: string
TickSize?: number,
TransferRate?: number,
Domain?: string
}

export interface SignerListLedgerEntry {
LedgerEntryType: 'SignerList',
OwnerNode: string,
SignerQuorum: number,
SignerEntries: SignerEntry[],
SignerListID: number,
PreviousTxnID: string,
PreviousTxnLgrSeq: number
}

// TODO: Add the other ledger entry types, then remove the `any` fallback
// see https://ripple.com/build/ledger-format/#ledger-object-types
export type LedgerEntry =
PayChannelLedgerEntry |
AccountRootLedgerEntry |
SignerListLedgerEntry |
any
17 changes: 17 additions & 0 deletions src/common/types/objects/orders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Amount} from './amounts'
import {Memo} from './memos'

export type FormattedOrderSpecification = {
direction: string,
quantity: Amount,
totalPrice: Amount,
immediateOrCancel?: boolean,
fillOrKill?: boolean,
expirationTime?: string,
orderToReplace?: number,
memos?: Memo[],
// If enabled, the offer will not consume offers that exactly match it, and
// instead becomes an Offer node in the ledger. It will still consume offers
// that cross it.
passive?: boolean
}
16 changes: 16 additions & 0 deletions src/common/types/objects/queue_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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[]
}
30 changes: 30 additions & 0 deletions src/common/types/objects/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {Memo} from './memos'

export type WeightedSigner = {
address: string,
weight: number
}

export type Signers = {
threshold?: number,
weights: WeightedSigner[]
}

export type FormattedSettings = {
passwordSpent?: boolean,
requireDestinationTag?: boolean,
requireAuthorization?: boolean,
disallowIncomingXRP?: boolean,
disableMasterKey?: boolean,
enableTransactionIDTracking?: boolean,
noFreeze?: boolean,
globalFreeze?: boolean,
defaultRipple?: boolean,
emailHash?: string|null,
messageKey?: string,
domain?: string,
transferRate?: number|null,
regularKey?: string,
signers?: Signers,
memos?: Memo[]
}
10 changes: 0 additions & 10 deletions src/common/types/objects/signers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
export interface SignerList {
LedgerEntryType: string,
OwnerNode: string,
SignerQuorum: number,
SignerEntries: SignerEntry[],
SignerListID: number,
PreviousTxnID: string,
PreviousTxnLgrSeq: number
}

export interface SignerEntry {
Account: string,
SignerWeight: number
Expand Down
25 changes: 13 additions & 12 deletions src/ledger/ledger.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import {validate} from '../common'
import parseLedger from './parse/ledger'
import {GetLedger} from './types'
import {FormattedLedger, parseLedger} from './parse/ledger'
import {RippleAPI} from '../api'

export type LedgerOptions = {
export type GetLedgerOptions = {
ledgerVersion?: number,
includeAllData?: boolean,
includeTransactions?: boolean,
includeState?: boolean
}


function getLedger(options: LedgerOptions = {}): Promise<GetLedger> {
async function getLedger(
this: RippleAPI, options: GetLedgerOptions = {}
): Promise<FormattedLedger> {
// 1. Validate
validate.getLedger({options})

const request = {
command: 'ledger',
// 2. Make Request
const response = await this._request('ledger', {
ledger_index: options.ledgerVersion || 'validated',
expand: options.includeAllData,
transactions: options.includeTransactions,
accounts: options.includeState
}

return this.connection.request(request).then(response =>
parseLedger(response.ledger))
})
// 3. Return Formatted Response
return parseLedger(response.ledger)
}


export default getLedger
Loading