public static Hash256 CalculateId(AccountId low, AccountId high, CurrencyCode currencyCode) { Span <byte> buffer = stackalloc byte[62]; System.Buffers.Binary.BinaryPrimitives.WriteUInt16BigEndian(buffer, 0x0072); low.CopyTo(buffer.Slice(2)); high.CopyTo(buffer.Slice(22)); currencyCode.CopyTo(buffer.Slice(42)); return(CalculateId(buffer)); }
public static Hash256 CalculateOfferId(CurrencyCode takerPaysCurrency, CurrencyCode takerGetsCurrency, AccountId takerPaysIssuer, AccountId takerGetsIssuer, ulong offers) { // The first page of an Offer Directory has a special ID: the higher 192 bits define the order book, and the remaining 64 bits define the exchange rate of the offers in that directory. // (The ID is big-endian, so the book is in the more significant bits, which come first, and the quality is in the less significant bits which come last.) // This provides a way to iterate through an order book from best offers to worst.Specifically: the first 192 bits are the first 192 bits of the SHA-512Half of the following values, concatenated in order: // //The Book Directory space key(0x0042) //The 160-bit currency code from the TakerPaysCurrency //The 160-bit currency code from the TakerGetsCurrency //The AccountID from the TakerPaysIssuer //The AccountID from the TakerGetsIssuer //The lower 64 bits of an Offer Directory's ID represent the TakerPays amount divided by TakerGets amount from the offer(s) in that directory as a 64-bit number in the XRP Ledger's internal amount format. // Span <byte> buffer = stackalloc byte[38]; System.Buffers.Binary.BinaryPrimitives.WriteUInt16BigEndian(buffer, 0x0042); takerPaysCurrency.CopyTo(buffer.Slice(2)); takerGetsCurrency.CopyTo(buffer.Slice(22)); takerPaysIssuer.CopyTo(buffer.Slice(42)); takerGetsIssuer.CopyTo(buffer.Slice(62)); Hash256 hash = CalculateId(buffer); return(hash); }