Show / Hide Table of Contents

Class MemoRules

The limits a node puts on Memos before it will accept a transaction at all.

Inheritance
object
MemoRules
Namespace: Xrpl.Models.Transactions
Assembly: Xrpl.dll
Syntax
public static class MemoRules
Remarks

These are local checks in rippled's passesLocalChecks → isMemoOkay (src/libxrpl/protocol/STTx.cpp). A transaction that fails them is not relayed, never reaches a ledger and costs no fee - but the consumer only finds out after building, autofilling and signing it, and the refusal does not say which field was at fault. Checking the same rules before signing turns that into an exception that names the problem.

Two of the five rules the node applies are already enforced by the binary codec, so they are deliberately not repeated here: a member other than MemoType, MemoData or MemoFormat inside a Memo is refused when the blob is built, and so is a value that is not hex. Re-checking them would mean two places to keep in step with one truth.

Fields

| Edit this page View Source

MaxSerializedLength

The largest the serialized Memos array may be, in bytes.

Declaration
public const int MaxSerializedLength = 1024
Field Value
Type Description
int
Remarks

The limit is on the array as a whole, so several memos do not raise it. In practice this leaves 1019 bytes of MemoData in a single memo carrying nothing else.

Methods

| Edit this page View Source

TryGetSerializedLength(IEnumerable<MemoWrapper>, out int)

Measures the SDK's typed Memos (TransactionCommon.Memos, MemoWrapper elements) with the same rules as TryGetSerializedLength(object, out int).

Declaration
public static bool TryGetSerializedLength(IEnumerable<MemoWrapper> memos, out int length)
Parameters
Type Name Description
IEnumerable<MemoWrapper> memos

The memos of a transaction, or null.

int length

The serialized length in bytes, to compare with MaxSerializedLength; 0 when the method returns false.

Returns
Type Description
bool

false for null, an empty sequence, a MemoWrapper without a Memo, or a memo whose members are not hex. A member left null is not written, so a memo of MemoData alone is measured without MemoType and MemoFormat.

| Edit this page View Source

TryGetSerializedLength(object, out int)

Measures a Memos array the way the node measures it, so a caller can show how much room is left before the limit instead of finding out when signing is refused.

Declaration
public static bool TryGetSerializedLength(object memos, out int length)
Parameters
Type Name Description
object memos

The value of the transaction's Memos field: a collection of { "Memo": { ... } } elements (or the equivalent JSON array), the shape Validate(object) accepts. A transaction's typed Memos (MemoWrapper elements) go through the TryGetSerializedLength(IEnumerable<MemoWrapper>, out int) overload, which the compiler checks; this one takes anything and answers false for what is not an array of memos, such as a string or a single memo.

int length

The length in bytes of the array as it would be serialized in the transaction, to compare with MaxSerializedLength; 0 when the method returns false.

Returns
Type Description
bool

false when there is nothing to measure: memos is null, not an array, empty, holds an element that is not a Memo object, or holds content the binary codec cannot serialize (a value that is not hex, say), or is an object System.Text.Json cannot convert to JSON (a double.NaN value, a getter that throws). The method throws nothing but critical runtime failures such as System.OutOfMemoryException.

Remarks

This is the figure Validate(object) compares with the limit, so a form and the signing check cannot disagree. rippled serializes the array with STArray::add: each element is its object start marker, the fields, and the object end marker; the array's own markers are not part of the length it compares.

Each field costs one byte of field id plus its length prefix (one byte up to 192 bytes, two up to 12480) plus the value. A memo costs two more for its start and end markers. A single memo of n bytes of MemoData with a ten-byte MemoFormat such as text/plain and no MemoType therefore measures n + 17 once n is 193 or more, and a memo of data alone measures n + 5 (n + 4 below 193, where the length prefix is one byte).

| Edit this page View Source

Validate(object)

Checks a transaction's Memos against the rules a node applies locally.

Declaration
public static void Validate(object memos)
Parameters
Type Name Description
object memos

The value of the transaction's Memos field, or null.

Exceptions
Type Condition
ValidationException

When the array is too large, an element is not a Memo object, or a MemoType/MemoFormat decodes to something a URL may not contain.

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