Add binary codec and transaction models for MPT#131
Open
Conversation
baf2e82 to
841449f
Compare
Add a 192-bit (24-byte) hash type required by MPT fields such as MPTokenIssuanceID. Follows the same implementation pattern as Hash128/Hash160/Hash256 with full trait coverage (Hash, XRPLType, TryFromParser, TryFrom<&str>, Display, AsRef<[u8]>) and unit tests.
Add Hash192 type (replacing unused UInt192 at type code 21), four MPT transaction types (MPTokenIssuanceCreate/Destroy/Set/Authorize), two MPT ledger entry types (MPTokenIssuance/MPToken), and seven MPT-related fields (MPTokenIssuanceID, ShareMPTID, MaximumAmount, MPTAmount, AssetScale, MPTokenMetadata, Holder) to definitions.json and types.rs.
Add MPTokenAuthorize, MPTokenIssuanceCreate, MPTokenIssuanceDestroy, and MPTokenIssuanceSet to the TransactionType enum for use by MPT transaction models.
Add the MPTokenIssuanceCreate transaction with fields for asset_scale, maximum_amount, transfer_fee, and mptoken_metadata. Includes flags (TfMPTCanLock, TfMPTRequireAuth, TfMPTCanEscrow, TfMPTCanTrade, TfMPTCanTransfer, TfMPTCanClawback), transfer fee validation, builder methods, and serde roundtrip tests. Also adds InvalidFlagCombination variant to XRPLModelException for use by MPTokenIssuanceSet validation.
Add the MPTokenIssuanceDestroy transaction with mptoken_issuance_id field. Uses NoFlags since this transaction has no flag-specific behavior. Includes builder method, serde roundtrip, and validation tests.
Add the MPTokenIssuanceSet transaction with mptoken_issuance_id and optional holder fields. Includes TfMPTLock/TfMPTUnlock flags with validation that prevents setting both simultaneously. Builder methods, serde roundtrip, and conflict detection tests included.
Add the MPTokenAuthorize transaction with mptoken_issuance_id and optional holder fields. Includes TfMPTUnauthorize flag for opt-out flows. Builder methods, serde roundtrip, holder opt-in, and deauthorize flow tests included.
Add MPToken (account balance) and MPTokenIssuance (issuance definition) ledger entry types with full serde support, LedgerEntryType enum variants, and LedgerEntry enum variants. Includes serde roundtrip and ledger entry type tests for both objects.
Tests cover: - Field name encoding/decoding for all 7 new MPT fields (Hash192, AccountID, UInt8, UInt64, Blob types) - Transaction type code resolution (codes 54-57) - Ledger entry type code resolution (codes 126-127) - Field instance metadata validation - Full encode() roundtrip for all 4 MPT transaction types with hex pattern verification - encode_for_signing() with signing prefix - Flag serialization (combined TfMPTCanTransfer | TfMPTCanLock) - Deterministic encoding output
841449f to
7925f94
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
High Level Overview of Change
Full MPT (Multi-Purpose Token) support for the binary codec and transaction/ledger models:
Hash192type in the binary codec (24-byte fixed-length hash forMPTokenIssuanceID)definitions.jsonwith MPT transaction types, ledger entry types, and field definitionsMPTokenIssuanceCreate,MPTokenIssuanceDestroy,MPTokenIssuanceSet,MPTokenAuthorizeMPToken,MPTokenIssuanceCloses #119
Context of Change
The XRPL MPT amendment introduces four new transaction types (codes 54-57) and two new ledger entry types (codes 126-127). This required:
A new
Hash192type -- MPTokenIssuanceID is a 24-byte (192-bit) hash, which didn't exist in the codec. Followed the same pattern asHash128/Hash160/Hash256.Seven new field definitions in
definitions.json:MPTokenIssuanceID(Hash192),ShareMPTID(Hash192),Holder(AccountID),AssetScale(UInt8),MaximumAmount(UInt64),MPTAmount(UInt64),MPTokenMetadata(Blob).Transaction models following existing patterns in the codebase (
CommonFieldswith#[serde(flatten)],ValidateCurrenciesderive macro, builder methods, flag enums withserde_repr).Validation logic where appropriate:
MPTokenIssuanceCreatevalidatestransfer_fee <= 50000,MPTokenIssuanceSetrejects mutually exclusiveTfMPTLock+TfMPTUnlockflags.The
UInt192type name indefinitions.jsonwas renamed toHash192to match the rippled naming convention (fixed-length hashes use theHashprefix, notUInt).Type of Change
Before / After
Before:
TransactionTypeenumAfter:
Hash192type handles 24-byte hashes correctly (fixed-length, no VL prefix)encode/encode_for_signing/encode_for_multisigning)MPTokenandMPTokenIssuanceledger objects deserialize from JSONTest Plan
All pass with zero warnings and zero failures. The binary codec tests verify:
encode()for all 4 transaction types with assertion on specific hex patternsencode_for_signing()prefix verificationencode_for_multisigning()prefix and suffix verification