feat(types): add LedgerClosedEvent and export more types (#1333)

- Export AccountInfoResponse and other types
This commit is contained in:
Elliot Lee
2020-11-23 18:58:05 -08:00
committed by GitHub
parent 33fb35138f
commit 2ba31c5b75
4 changed files with 50 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
import { import {
RippleAPI, RippleAPI,
AccountInfoResponse, AccountInfoResponse,
LedgerClosedEvent LedgerClosedEvent
} from '../../dist/npm' } from '../../dist/npm'
import https = require('https') import https = require('https')
@@ -22,14 +22,14 @@ import https = require('https')
* A) `tec`: The transaction was included in a ledger but only claimed the transaction fee * A) `tec`: The transaction was included in a ledger but only claimed the transaction fee
* B) `tesSUCCESS` but unexpected result: The transaction was successful but did not have the expected result. This generally does not occur for XRP-to-XRP payments * B) `tesSUCCESS` but unexpected result: The transaction was successful but did not have the expected result. This generally does not occur for XRP-to-XRP payments
* C) The transaction was not, and never will be, included in a validated ledger [3C] * C) The transaction was not, and never will be, included in a validated ledger [3C]
* *
* References: * References:
* - https://xrpl.org/reliable-transaction-submission.html * - https://xrpl.org/reliable-transaction-submission.html
* - https://xrpl.org/send-xrp.html * - https://xrpl.org/send-xrp.html
* - https://xrpl.org/look-up-transaction-results.html * - https://xrpl.org/look-up-transaction-results.html
* - https://xrpl.org/get-started-with-rippleapi-for-javascript.html * - https://xrpl.org/get-started-with-rippleapi-for-javascript.html
* - https://xrpl.org/monitor-incoming-payments-with-websocket.html * - https://xrpl.org/monitor-incoming-payments-with-websocket.html
* *
* For the implementation in this example, we have made the following decisions: * For the implementation in this example, we have made the following decisions:
* 1) The script will choose the account sequence and LastLedgerSequence numbers automatically. We allow ripple-lib to choose the fee. * 1) The script will choose the account sequence and LastLedgerSequence numbers automatically. We allow ripple-lib to choose the fee.
* Payments are defined upfront, and idempotency is not needed. If the script is run a second time, duplicate payments will result. * Payments are defined upfront, and idempotency is not needed. If the script is run a second time, duplicate payments will result.
@@ -43,13 +43,13 @@ reliableTransactionSubmissionExample()
async function reliableTransactionSubmissionExample() { async function reliableTransactionSubmissionExample() {
/** /**
* Array of payments to execute. * Array of payments to execute.
* *
* For brevity, these are XRP-to-XRP payments, taking a source, destination, and an amount in drops. * For brevity, these are XRP-to-XRP payments, taking a source, destination, and an amount in drops.
* *
* The script will attempt to make all of these payments as quickly as possible, and report the final status of each. Transactions that fail are NOT retried. * The script will attempt to make all of these payments as quickly as possible, and report the final status of each. Transactions that fail are NOT retried.
*/ */
const payments = [] const payments = []
const sourceAccount = (await generateTestnetAccount()).account const sourceAccount = (await generateTestnetAccount()).account
console.log(`Generated new Testnet account: ${sourceAccount.classicAddress}/${sourceAccount.secret}`) console.log(`Generated new Testnet account: ${sourceAccount.classicAddress}/${sourceAccount.secret}`)
// Send amounts from 1 drop to 10 drops // Send amounts from 1 drop to 10 drops

View File

@@ -451,4 +451,29 @@ class RippleAPI extends EventEmitter {
isValidSecret = schemaValidator.isValidSecret isValidSecret = schemaValidator.isValidSecret
} }
export {RippleAPI} export {
RippleAPI
}
export type {
AccountObjectsRequest,
AccountObjectsResponse,
AccountOffersRequest,
AccountOffersResponse,
AccountInfoRequest,
AccountInfoResponse,
AccountLinesRequest,
AccountLinesResponse,
BookOffersRequest,
BookOffersResponse,
GatewayBalancesRequest,
GatewayBalancesResponse,
LedgerRequest,
LedgerResponse,
LedgerDataRequest,
LedgerDataResponse,
LedgerEntryRequest,
LedgerEntryResponse,
ServerInfoRequest,
ServerInfoResponse
}

View File

@@ -21,3 +21,17 @@ export interface Ledger {
accountState?: any[] accountState?: any[]
validated?: boolean validated?: boolean
} }
// https://xrpl.org/subscribe.html#ledger-stream
export type LedgerClosedEvent = {
type: 'ledgerClosed'
fee_base: number
fee_ref: number
ledger_hash: string
ledger_index: number
ledger_time: number
reserve_base: number
reserve_inc: number
txn_count: number
validated_ledgers: string
}

View File

@@ -1,6 +1,8 @@
export {RippleAPI} from './api' export * from './api'
export {FormattedTransactionType} from './transaction/types' export * from './transaction/types'
export * from './common/types/objects/ledger'
// Broadcast api is experimental // Broadcast api is experimental
export {RippleAPIBroadcast} from './broadcast' export {RippleAPIBroadcast} from './broadcast'