import { Wallet, XrplNetwork } from 'xpring-common-js'; import { XRPDropsAmount } from './Generated/web/org/xrpl/rpc/v1/amount_pb'; import { AccountRoot } from './Generated/web/org/xrpl/rpc/v1/ledger_objects_pb'; import { Transaction } from './Generated/web/org/xrpl/rpc/v1/transaction_pb'; import { GetFeeResponse } from './Generated/web/org/xrpl/rpc/v1/get_fee_pb'; import TransactionStatus from './shared/transaction-status'; import RawTransactionStatus from './shared/raw-transaction-status'; import { GrpcNetworkClientInterface } from './network-clients/grpc-network-client-interface'; import TransactionResult from './shared/transaction-result'; import CoreXrplClientInterface from './core-xrpl-client-interface'; /** * CoreXrplClient is a client which supports the core, common functionality for interacting with the XRP Ledger. */ export default class CoreXrplClient implements CoreXrplClientInterface { readonly networkClient: GrpcNetworkClientInterface; readonly network: XrplNetwork; /** * Creates a new CoreXrplClient. * * The CoreXrplClient will use gRPC to communicate with the given endpoint. * * @param grpcUrl The URL of the gRPC instance to connect to. * @param network The network this XrpClient is connecting to. * @param forceWeb If `true`, then we will use the gRPC-Web client even when on Node. Defaults to false. This is mainly for testing and in the future will be removed when we have browser testing. */ static coreXrplClientWithEndpoint(grpcUrl: string, network: XrplNetwork, forceWeb?: boolean): CoreXrplClient; /** * Creates a new CoreXrplClient with a custom network client implementation. * * @param networkClient A network client which will manage remote RPCs to Rippled. * @param network The network this XrpClient is connecting to. */ constructor(networkClient: GrpcNetworkClientInterface, network: XrplNetwork); /** * Retrieves the sequence number of the current open ledger in this rippled node. * @see https://xrpl.org/ledgers.html#open-closed-and-validated-ledgers */ getOpenLedgerSequence(): Promise; /** * Retrieve the latest validated ledger sequence on the XRP Ledger. * * Note: This call will throw if the given account does not exist on the ledger at the current time. It is the * *caller's responsibility* to ensure this invariant is met. * * Note: The input address *must* be in a classic address form. Inputs are not checked to this internal method. * * TODO: The above requirements are onerous, difficult to reason about and the logic of this method is * brittle. Replace this method's implementation when rippled supports a `ledger` RPC via gRPC. * * @param address An address that exists at the current time. The address is unchecked and must be a classic address. * @returns The index of the latest validated ledger. * @throws XrpException If there was a problem communicating with the XRP Ledger. */ getLatestValidatedLedgerSequence(address: string): Promise; /** * Retrieves the raw transaction status for the given transaction hash. * * @param transactionHash: The hash of the transaction. * @returns The status of the given transaction. */ getRawTransactionStatus(transactionHash: string): Promise; /** * Retrieves the minimum transaction cost for a reference transaction to be queued for a later ledger, * represented in drops of XRP. * @see https://xrpl.org/rippleapi-reference.html#transaction-fees * @see https://xrpl.org/fee.html#response-format */ getMinimumFee(): Promise; /** * Reports the current state of the open-ledger requirements for the transaction cost. * @see https://xrpl.org/rippleapi-reference.html#transaction-fees * @see https://xrpl.org/fee.html#response-format */ getFee(): Promise; /** * Returns the AccountRoot object containing information about this XRPL account. * @see https://xrpl.org/account_info.html#account_info * * @param address The XRPL account for which to retrieve information. */ getAccountData(address: string): Promise; /** * Populates the required fields common to all transaction types. * * @see https://xrpl.org/transaction-common-fields.html * * Note: The returned Transaction object must still be assigned transaction-specific details. * Some transaction types require a different fee (or no fee), in which case the fee should be overwritten appropriately * when constructing the transaction-specific details. (See https://xrpl.org/transaction-cost.html) * * @param wallet The wallet that will sign and submit this transaction. * @returns A promise which resolves to a Transaction protobuf with the required common fields populated. */ prepareBaseTransaction(wallet: Wallet): Promise; /** * Signs the provided transaction using the wallet and submits to the XRPL network. * * @param transaction The transaction to be signed and submitted. * @param wallet The wallet that will sign and submit this transaction. * @returns A promise which resolves to a string representing the hash of the submitted transaction. */ signAndSubmitTransaction(transaction: Transaction, wallet: Wallet): Promise; /** * Returns a detailed TransactionResult for a given XRPL transaction hash. * * @param transactionHash The transaction hash to populate a TransactionResult for. * @returns A Promise which resolves to a TransactionResult associated with the given transaction hash. */ getTransactionResult(transactionHash: string): Promise; /** * Retrieve the transaction status for a Transaction given a transaction hash. * * Note: This method will only work for Payment type transactions which do not have the tf_partial_payment attribute set. * @see https://xrpl.org/payment.html#payment-flags * * @param transactionHash The hash of the transaction. * @returns A TransactionStatus containing the status of the given transaction. */ getTransactionStatus(transactionHash: string): Promise; /** * Waits for a transaction to complete and returns a TransactionResult. * * @param transactionHash The transaction to wait for. * @param wallet The wallet sending the transaction. * * @returns A Promise resolving to a TransactionResult containing the results of the transaction associated with * the given transaction hash. */ getFinalTransactionResultAsync(transactionHash: string, wallet: Wallet): Promise; /** * Determines the current TransactionStatus from a RawTransactionStatus (translating from * a rippled transaction status code such as `tesSUCCESS`, in conjunction with validated * status, into a TransactionStatus enum instance) * * @param rawTransactionStatus */ private getFinalTransactionStatus; private isMalformedTransaction; /** * The core logic of reliable submission. Polls the ledger until the result of the transaction * can be considered final, meaning it has either been included in a validated ledger, or the * transaction's lastLedgerSequence has been surpassed by the latest ledger sequence (meaning it * will never be included in a validated ledger.) * * @param transactionHash The hash of the transaction being awaited. * @param sender The address used to obtain the latest ledger sequence. */ waitForFinalTransactionOutcome(transactionHash: string, sender: Wallet): Promise<{ rawTransactionStatus: RawTransactionStatus; lastLedgerPassed: boolean; }>; /** * Helper function. Sets/clears a flag value. * @param flag The desired flag that is being changed. * @param enable Whether the flag is being enabled (true if enabling, false if disabling). * @param wallet The wallet associated with the XRPL account enabling Require Authorization and that will sign the request. * @returns A promise which resolves to a TransactionResult object that represents the result of this transaction. */ changeFlag(flag: number, enable: boolean, wallet: Wallet): Promise; }