Expand description
Token payment metadata and helpers.
This module defines the versioned TokenPaymentInfo wrapper used to describe how a
client intends to pay with tokens for an operation (for example, creating,
transferring, purchasing, or updating the price of a document/NFT).
It captures which token to use, optional price bounds, and who covers gas fees.
The enum is versioned to allow future evolution without breaking callers. The
current implementation is v0::TokenPaymentInfoV0. Accessors are provided via
v0::v0_accessors::TokenPaymentInfoAccessorsV0, and convenience methods (such
as token_id() and is_valid_for_required_cost()) are available through
methods::v0::TokenPaymentInfoMethodsV0.
Typical usage:
use dpp::tokens::gas_fees_paid_by::GasFeesPaidBy;
use dpp::data_contract::TokenContractPosition;
use dpp::tokens::token_payment_info::{TokenPaymentInfo, v0::TokenPaymentInfoV0};
// Client indicates payment preferences for a transition
let info: TokenPaymentInfo = TokenPaymentInfoV0 {
// `None` => use a token defined on the current contract
payment_token_contract_id: None,
// Which token (by position/index) on the contract to use
token_contract_position: 0u16,
// Optional bounds to guard against unexpected price changes
minimum_token_cost: None,
maximum_token_cost: Some(1_000u64.into()),
// Who pays gas: user, contract owner, or prefer contract owner
gas_fees_paid_by: GasFeesPaidBy::DocumentOwner,
}.into();Deserialization from a platform BTreeMap<String, Value> requires a
$formatVersion key. For V0 the map may contain:
paymentTokenContractId(Identifieras bytes)tokenContractPosition(u16)minimumTokenCost(u64)maximumTokenCost(u64)gasFeesPaidBy(one of:"DocumentOwner","ContractOwner","PreferContractOwner")
Unknown $formatVersion values yield an UnknownVersionMismatch error.
Modules§
Enums§
- Token
Payment Info - Versioned container describing how a client intends to pay with tokens.