Show / Hide Table of Contents

Class BookIndex

A set of order books - each a pair of assets, in the open book or a domain - built from a whole ledger, from a list of assets, or from the trust lines of the accounts involved.

Inheritance
object
BookIndex
Implements
IBookIndex
Namespace: Xrpl.Amounts
Assembly: Xrpl.dll
Syntax
public sealed class BookIndex : IBookIndex
Remarks

FromLedgerAsync(IXrplClient, LedgerIndex, CancellationToken) repeats OrderBookDB: every book directory and every AMM pool of a ledger, which is what the node's path finder searches. It reads the whole ledger, which suits a private node, a standalone one or a test network. Observe(Meta) adds the books later transactions create, as the node does between its full rebuilds.

FromAssetsAsync(IXrplClient, IEnumerable<IssuedCurrency>, string, LedgerIndex, CancellationToken) checks every pair of the assets given, and FromAccountsAsync(IXrplClient, IEnumerable<string>, string, LedgerIndex, CancellationToken) the assets of the accounts' trust lines: cheap on mainnet, but a path through a book they leave out is not found.

Fields

| Edit this page View Source

MaxProbeAssets

The most assets FromAssetsAsync(IXrplClient, IEnumerable<IssuedCurrency>, string, LedgerIndex, CancellationToken) checks: the pairs grow with the square of them.

Declaration
public const int MaxProbeAssets = 50
Field Value
Type Description
int

Properties

| Edit this page View Source

Count

The number of books in the index.

Declaration
public int Count { get; }
Property Value
Type Description
int

Methods

| Edit this page View Source

Add(IssuedCurrency, IssuedCurrency, string)

Adds a book: offers that take takerPays and give takerGets.

Declaration
public void Add(Common.IssuedCurrency takerPays, Common.IssuedCurrency takerGets, string domainId = null)
Parameters
Type Name Description
Common.IssuedCurrency takerPays

What the book's offers ask for.

Common.IssuedCurrency takerGets

What they give.

string domainId

The permissioned domain of the book; null for the open book.

| Edit this page View Source

AddPool(IssuedCurrency, IssuedCurrency)

Adds a pool: an AMM trades both ways between its two assets, in the open book only.

Declaration
public void AddPool(Common.IssuedCurrency asset, Common.IssuedCurrency asset2)
Parameters
Type Name Description
Common.IssuedCurrency asset
Common.IssuedCurrency asset2
| Edit this page View Source

BooksFrom(IssuedCurrency, string)

The assets of the books whose offers take takerPays: the books a holder of that asset can sell it into.

Declaration
public IReadOnlyCollection<Common.IssuedCurrency> BooksFrom(Common.IssuedCurrency takerPays, string domainId)
Parameters
Type Name Description
Common.IssuedCurrency takerPays

The asset sold into the books.

string domainId

The permissioned domain whose books to list; null for the open ones.

Returns
Type Description
IReadOnlyCollection<Common.IssuedCurrency>
| Edit this page View Source

FromAccountsAsync(IXrplClient, IEnumerable<string>, string, LedgerIndex, CancellationToken)

The books between the assets the accounts' trust lines hold or issue and the MPTs they issue or hold, XRP included, found as FromAssetsAsync(IXrplClient, IEnumerable<IssuedCurrency>, string, LedgerIndex, CancellationToken) finds them: a guess at the books a payment between these accounts can use.

Declaration
public static Task<BookIndex> FromAccountsAsync(IXrplClient client, IEnumerable<string> accounts, string domainId = null, LedgerIndex ledger = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
IXrplClient client

The node to read from.

IEnumerable<string> accounts

The accounts, usually the payment's source and destination.

string domainId

A permissioned domain whose books to check too; null for the open books only.

LedgerIndex ledger

The ledger to read; the last validated one when null.

CancellationToken cancellationToken

Cancels the reads.

Returns
Type Description
Task<BookIndex>
Remarks

A line gives the peer's currency when the account holds some or trusts the peer for it, and the account's own currency when the account owes some or the peer trusts it; so a gateway's lines to its holders give its own currencies once each. More than MaxProbeAssets assets fail as in FromAssetsAsync(IXrplClient, IEnumerable<IssuedCurrency>, string, LedgerIndex, CancellationToken).

| Edit this page View Source

FromAssetsAsync(IXrplClient, IEnumerable<IssuedCurrency>, string, LedgerIndex, CancellationToken)

The books between the assets given, XRP included: each ordered pair checked for an offer with book_offers, and for a pool with amm_info.

Declaration
public static Task<BookIndex> FromAssetsAsync(IXrplClient client, IEnumerable<Common.IssuedCurrency> assets, string domainId = null, LedgerIndex ledger = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
IXrplClient client

The node to read from.

IEnumerable<Common.IssuedCurrency> assets

The assets; XRP is added.

string domainId

A permissioned domain whose books to check too; null for the open books only.

LedgerIndex ledger

The ledger to read; the last validated one when null.

CancellationToken cancellationToken

Cancels the reads.

Returns
Type Description
Task<BookIndex>
Remarks

book_offers leaves out offers whose owner holds nothing, so a book of only such offers is not found. The pairs grow with the square of the assets, so at most MaxProbeAssets assets are accepted, XRP included.

Exceptions
Type Condition
ArgumentException

More than MaxProbeAssets distinct assets.

| Edit this page View Source

FromLedgerAsync(IXrplClient, LedgerIndex, CancellationToken)

Every book directory and AMM pool of a ledger, as rippled's OrderBookDB builds its index: read with ledger_data, the whole ledger page by page.

Declaration
public static Task<BookIndex> FromLedgerAsync(IXrplClient client, LedgerIndex ledger = null, CancellationToken cancellationToken = default)
Parameters
Type Name Description
IXrplClient client

The node to read from.

LedgerIndex ledger

The ledger to read; the last validated one when null.

CancellationToken cancellationToken

Cancels the reads.

Returns
Type Description
Task<BookIndex>
| Edit this page View Source

FromSnapshot(DexSnapshot)

The books of snapshot: its offers' books, hybrid offers in both, and its pools both ways.

Declaration
public static BookIndex FromSnapshot(DexSnapshot snapshot)
Parameters
Type Name Description
DexSnapshot snapshot
Returns
Type Description
BookIndex
| Edit this page View Source

HasBookToXrp(IssuedCurrency, string)

Whether a book sells takerPays for XRP.

Declaration
public bool HasBookToXrp(Common.IssuedCurrency takerPays, string domainId)
Parameters
Type Name Description
Common.IssuedCurrency takerPays
string domainId
Returns
Type Description
bool
| Edit this page View Source

Observe(Meta)

Adds the books a transaction created - a book directory's first offer, a new AMM - as the node adds them to its index between full rebuilds. Books are never removed.

Declaration
public void Observe(Meta meta)
Parameters
Type Name Description
Meta meta

The transaction's metadata.

Implements

IBookIndex
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX