use crate::c;
mod control;
mod etxn;
mod float;
mod hook;
mod internal;
mod ledger;
mod otxn;
mod slot;
mod state;
mod sto;
mod trace;
mod util;
pub use control::*;
pub use etxn::*;
pub use float::*;
pub use hook::*;
pub(crate) use internal::*;
pub use ledger::*;
pub use otxn::*;
pub use slot::*;
pub use state::*;
pub use sto::*;
pub use trace::*;
pub use util::*;
pub const TF_CANONICAL: u32 = c::tfCANONICAL;
pub const ACC_ID_LEN: usize = 20;
pub const CURRENCY_CODE_SIZE: usize = 20;
pub const LEDGER_HASH_LEN: usize = 32;
pub const KEYLET_LEN: usize = 34;
pub const STATE_KEY_LEN: usize = 32;
pub const NONCE_LEN: usize = 32;
pub const HASH_LEN: usize = 32;
pub const AMOUNT_LEN: usize = 48;
pub const PREPARE_PAYMENT_SIMPLE_SIZE: usize = c::PREPARE_PAYMENT_SIMPLE_SIZE as _;
pub const EMIT_DETAILS_SIZE: usize = 105;
pub const XFL_LEN: usize = 8;
pub type Buffer<const T: usize> = [u8; T];
pub type AccountId = Buffer<ACC_ID_LEN>;
pub type Hash = Buffer<HASH_LEN>;
pub type Keylet = Buffer<KEYLET_LEN>;
pub type StateKey = Buffer<STATE_KEY_LEN>;
pub type Nonce = Buffer<NONCE_LEN>;
pub type Amount = Buffer<AMOUNT_LEN>;
pub type TxnPaymentSimple = Buffer<PREPARE_PAYMENT_SIMPLE_SIZE>;
pub type EmitDetails = Buffer<EMIT_DETAILS_SIZE>;
pub type CurrencyCode = Buffer<CURRENCY_CODE_SIZE>;
#[allow(missing_docs)]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum TxnType {
Payment = c::ttPAYMENT,
EscrowCreate = 1,
EscrowFinish = 2,
AccountSet = 3,
EscrowCancel = 4,
RegularKeySet = 5,
OfferCreate = 7,
OfferCancel = 8,
TicketCreate = 10,
TicketCancel = 11,
SignerListSet = 12,
PaychanCreate = 13,
PaychanFund = 14,
PaychanClaim = 15,
CheckCreate = 16,
CheckCash = 17,
CheckCancel = 18,
DepositPreauth = 19,
TrustSet = 20,
AccountDelete = 21,
HookSet = 22,
Amendment = 100,
Fee = 101,
UnlModify = 102,
}
#[allow(missing_docs)]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum AccountType {
Account = c::atACCOUNT,
Owner = c::atOWNER,
Destination = c::atDESTINATION,
Issuer = c::atISSUER,
Authorize = c::atAUTHORIZE,
Unauthorize = c::atUNAUTHORIZE,
Target = c::atTARGET,
RegularKey = c::atREGULARKEY,
PseudoCallback = c::atPSEUDOCALLBACK,
}
#[allow(missing_docs)]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum AmountType {
Amount = c::amAMOUNT,
Balance = c::amBALANCE,
LimitAmount = c::amLIMITAMOUNT,
TakerPays = c::amTAKERPAYS,
TakerGets = c::amTAKERGETS,
LowLimit = c::amLOWLIMIT,
HighLimit = c::amHIGHLIMIT,
Fee = c::amFEE,
SendMax = c::amSENDMAX,
DeliverMin = c::amDELIVERMIN,
MinimumOffer = c::amMINIMUMOFFER,
RippleEscrow = c::amRIPPLEESCROW,
DeliveredAmount = c::amDELIVEREDAMOUNT,
}
#[allow(missing_docs)]
#[derive(Clone, Copy)]
pub enum KeyletType<'a> {
Hook(&'a [u8]),
HookState(&'a [u8], &'a [u8]),
Account(&'a [u8]),
Amendments,
Child(&'a [u8]),
Skip(Option<(u32, u32)>),
Fees,
NegativeUnl,
Line(&'a [u8], &'a [u8], &'a [u8]),
Offer(&'a [u8], u32),
Quality(&'a [u8], u32, u32),
EmittedDir,
Signers(&'a [u8]),
Check(&'a [u8], u32),
DepositPreauth(&'a [u8], &'a [u8]),
Unchecked(&'a [u8]),
OwnerDir(&'a [u8]),
Page(&'a [u8], u32, u32),
Escrow(&'a [u8], u32),
Paychan(&'a [u8], &'a [u8], u32),
Emitted(&'a [u8]),
}
#[derive(Clone, Copy)]
pub enum FieldOrXrpAmount {
Field(FieldId),
XrpAmount,
NonXrpAmount,
}
#[derive(Clone, Copy)]
pub enum SlotTypeFlags {
Field,
XrpAmount,
}
#[allow(missing_docs)]
#[derive(Clone, Copy)]
#[repr(u32)]
pub enum FieldId {
CloseResolution = c::sfCloseResolution,
Method = c::sfMethod,
TransactionResult = c::sfTransactionResult,
TickSize = c::sfTickSize,
UNLModifyDisabling = c::sfUNLModifyDisabling,
HookResult = c::sfHookResult,
LedgerEntryType = c::sfLedgerEntryType,
TransactionType = c::sfTransactionType,
SignerWeight = c::sfSignerWeight,
TransferFee = c::sfTransferFee,
Version = c::sfVersion,
HookStateChangeCount = c::sfHookStateChangeCount,
HookEmitCount = c::sfHookEmitCount,
HookExecutionIndex = c::sfHookExecutionIndex,
HookApiVersion = c::sfHookApiVersion,
NetworkID = c::sfNetworkID,
Flags = c::sfFlags,
SourceTag = c::sfSourceTag,
Sequence = c::sfSequence,
PreviousTxnLgrSeq = c::sfPreviousTxnLgrSeq,
LedgerSequence = c::sfLedgerSequence,
CloseTime = c::sfCloseTime,
ParentCloseTime = c::sfParentCloseTime,
SigningTime = c::sfSigningTime,
Expiration = c::sfExpiration,
TransferRate = c::sfTransferRate,
WalletSize = c::sfWalletSize,
OwnerCount = c::sfOwnerCount,
DestinationTag = c::sfDestinationTag,
HighQualityIn = c::sfHighQualityIn,
HighQualityOut = c::sfHighQualityOut,
LowQualityIn = c::sfLowQualityIn,
LowQualityOut = c::sfLowQualityOut,
QualityIn = c::sfQualityIn,
QualityOut = c::sfQualityOut,
StampEscrow = c::sfStampEscrow,
BondAmount = c::sfBondAmount,
LoadFee = c::sfLoadFee,
OfferSequence = c::sfOfferSequence,
FirstLedgerSequence = c::sfFirstLedgerSequence,
LastLedgerSequence = c::sfLastLedgerSequence,
TransactionIndex = c::sfTransactionIndex,
OperationLimit = c::sfOperationLimit,
ReferenceFeeUnits = c::sfReferenceFeeUnits,
ReserveBase = c::sfReserveBase,
ReserveIncrement = c::sfReserveIncrement,
SetFlag = c::sfSetFlag,
ClearFlag = c::sfClearFlag,
SignerQuorum = c::sfSignerQuorum,
CancelAfter = c::sfCancelAfter,
FinishAfter = c::sfFinishAfter,
SignerListID = c::sfSignerListID,
SettleDelay = c::sfSettleDelay,
TicketCount = c::sfTicketCount,
TicketSequence = c::sfTicketSequence,
NFTokenTaxon = c::sfNFTokenTaxon,
MintedNFTokens = c::sfMintedNFTokens,
BurnedNFTokens = c::sfBurnedNFTokens,
HookStateCount = c::sfHookStateCount,
EmitGeneration = c::sfEmitGeneration,
LockCount = c::sfLockCount,
RewardTime = c::sfRewardTime,
RewardLgrFirst = c::sfRewardLgrFirst,
RewardLgrLast = c::sfRewardLgrLast,
IndexNext = c::sfIndexNext,
IndexPrevious = c::sfIndexPrevious,
BookNode = c::sfBookNode,
OwnerNode = c::sfOwnerNode,
BaseFee = c::sfBaseFee,
ExchangeRate = c::sfExchangeRate,
LowNode = c::sfLowNode,
HighNode = c::sfHighNode,
DestinationNode = c::sfDestinationNode,
Cookie = c::sfCookie,
ServerVersion = c::sfServerVersion,
NFTokenOfferNode = c::sfNFTokenOfferNode,
EmitBurden = c::sfEmitBurden,
HookInstructionCount = c::sfHookInstructionCount,
HookReturnCode = c::sfHookReturnCode,
ReferenceCount = c::sfReferenceCount,
RewardAccumulator = c::sfRewardAccumulator,
EmailHash = c::sfEmailHash,
TakerPaysCurrency = c::sfTakerPaysCurrency,
TakerPaysIssuer = c::sfTakerPaysIssuer,
TakerGetsCurrency = c::sfTakerGetsCurrency,
TakerGetsIssuer = c::sfTakerGetsIssuer,
LedgerHash = c::sfLedgerHash,
ParentHash = c::sfParentHash,
TransactionHash = c::sfTransactionHash,
AccountHash = c::sfAccountHash,
PreviousTxnID = c::sfPreviousTxnID,
LedgerIndex = c::sfLedgerIndex,
WalletLocator = c::sfWalletLocator,
RootIndex = c::sfRootIndex,
AccountTxnID = c::sfAccountTxnID,
NFTokenID = c::sfNFTokenID,
EmitParentTxnID = c::sfEmitParentTxnID,
EmitNonce = c::sfEmitNonce,
EmitHookHash = c::sfEmitHookHash,
BookDirectory = c::sfBookDirectory,
InvoiceID = c::sfInvoiceID,
Nickname = c::sfNickname,
Amendment = c::sfAmendment,
HookOn = c::sfHookOn,
Digest = c::sfDigest,
Channel = c::sfChannel,
ConsensusHash = c::sfConsensusHash,
CheckID = c::sfCheckID,
ValidatedHash = c::sfValidatedHash,
PreviousPageMin = c::sfPreviousPageMin,
NextPageMin = c::sfNextPageMin,
NFTokenBuyOffer = c::sfNFTokenBuyOffer,
NFTokenSellOffer = c::sfNFTokenSellOffer,
HookStateKey = c::sfHookStateKey,
HookHash = c::sfHookHash,
HookNamespace = c::sfHookNamespace,
HookSetTxnID = c::sfHookSetTxnID,
OfferID = c::sfOfferID,
EscrowID = c::sfEscrowID,
URITokenID = c::sfURITokenID,
Amount = c::sfAmount,
Balance = c::sfBalance,
LimitAmount = c::sfLimitAmount,
TakerPays = c::sfTakerPays,
TakerGets = c::sfTakerGets,
LowLimit = c::sfLowLimit,
HighLimit = c::sfHighLimit,
Fee = c::sfFee,
SendMax = c::sfSendMax,
DeliverMin = c::sfDeliverMin,
MinimumOffer = c::sfMinimumOffer,
RippleEscrow = c::sfRippleEscrow,
DeliveredAmount = c::sfDeliveredAmount,
NFTokenBrokerFee = c::sfNFTokenBrokerFee,
HookCallbackFee = c::sfHookCallbackFee,
LockedBalance = c::sfLockedBalance,
PublicKey = c::sfPublicKey,
MessageKey = c::sfMessageKey,
SigningPubKey = c::sfSigningPubKey,
TxnSignature = c::sfTxnSignature,
URI = c::sfURI,
Signature = c::sfSignature,
Domain = c::sfDomain,
FundCode = c::sfFundCode,
RemoveCode = c::sfRemoveCode,
ExpireCode = c::sfExpireCode,
CreateCode = c::sfCreateCode,
MemoType = c::sfMemoType,
MemoData = c::sfMemoData,
MemoFormat = c::sfMemoFormat,
Fulfillment = c::sfFulfillment,
Condition = c::sfCondition,
MasterSignature = c::sfMasterSignature,
UNLModifyValidator = c::sfUNLModifyValidator,
ValidatorToDisable = c::sfValidatorToDisable,
ValidatorToReEnable = c::sfValidatorToReEnable,
HookStateData = c::sfHookStateData,
HookReturnString = c::sfHookReturnString,
HookParameterName = c::sfHookParameterName,
HookParameterValue = c::sfHookParameterValue,
Blob = c::sfBlob,
Account = c::sfAccount,
Owner = c::sfOwner,
Destination = c::sfDestination,
Issuer = c::sfIssuer,
Authorize = c::sfAuthorize,
Unauthorize = c::sfUnauthorize,
RegularKey = c::sfRegularKey,
NFTokenMinter = c::sfNFTokenMinter,
EmitCallback = c::sfEmitCallback,
HookAccount = c::sfHookAccount,
Indexes = c::sfIndexes,
Hashes = c::sfHashes,
Amendments = c::sfAmendments,
NFTokenOffers = c::sfNFTokenOffers,
HookNamespaces = c::sfHookNamespaces,
Paths = c::sfPaths,
TransactionMetaData = c::sfTransactionMetaData,
CreatedNode = c::sfCreatedNode,
DeletedNode = c::sfDeletedNode,
ModifiedNode = c::sfModifiedNode,
PreviousFields = c::sfPreviousFields,
FinalFields = c::sfFinalFields,
NewFields = c::sfNewFields,
TemplateEntry = c::sfTemplateEntry,
Memo = c::sfMemo,
SignerEntry = c::sfSignerEntry,
NFToken = c::sfNFToken,
EmitDetails = c::sfEmitDetails,
Hook = c::sfHook,
Signer = c::sfSigner,
Majority = c::sfMajority,
DisabledValidator = c::sfDisabledValidator,
EmittedTxn = c::sfEmittedTxn,
HookExecution = c::sfHookExecution,
HookDefinition = c::sfHookDefinition,
HookParameter = c::sfHookParameter,
HookGrant = c::sfHookGrant,
Signers = c::sfSigners,
SignerEntries = c::sfSignerEntries,
Template = c::sfTemplate,
Necessary = c::sfNecessary,
Sufficient = c::sfSufficient,
AffectedNodes = c::sfAffectedNodes,
Memos = c::sfMemos,
NFTokens = c::sfNFTokens,
Hooks = c::sfHooks,
Majorities = c::sfMajorities,
DisabledValidators = c::sfDisabledValidators,
HookExecutions = c::sfHookExecutions,
HookParameters = c::sfHookParameters,
HookGrants = c::sfHookGrants,
}
#[derive(Clone, Copy)]
pub enum DataRepr {
AsUTF8 = 0,
AsHex = 1,
}
#[must_use]
pub enum Result<T> {
Ok(T),
Err(Error),
}
pub use self::Result::*;
impl<T> Result<T> {
#[inline(always)]
pub fn expect(self, msg: &[u8]) -> T {
match self {
Err(e) => rollback(msg, e.code() as _),
Ok(val) => val,
}
}
#[inline(always)]
pub fn unwrap(self) -> T {
match self {
Err(e) => rollback(b"error", e.code() as _),
Ok(val) => val,
}
}
#[inline(always)]
pub unsafe fn unwrap_unchecked(self) -> T {
match self {
Ok(val) => val,
Err(_) => core::hint::unreachable_unchecked(),
}
}
#[inline(always)]
pub fn unwrap_line_number(self) -> T {
match self {
Err(_) => rollback(b"error", line!().into()),
Ok(val) => val,
}
}
#[must_use]
#[inline(always)]
pub const fn is_ok(&self) -> bool {
matches!(*self, Ok(_))
}
#[must_use]
#[inline(always)]
pub const fn is_err(&self) -> bool {
!self.is_ok()
}
}
#[derive(Clone, Copy)]
#[repr(i32)]
pub enum Error {
OutOfBounds = c::OUT_OF_BOUNDS,
InternalError = c::INTERNAL_ERROR,
TooBig = c::TOO_BIG,
TooSmall = c::TOO_SMALL,
DoesntExist = c::DOESNT_EXIST,
NoFreeSlots = c::NO_FREE_SLOTS,
InvalidArgument = c::INVALID_ARGUMENT,
AlreadySet = c::ALREADY_SET,
PrerequisiteNotMet = c::PREREQUISITE_NOT_MET,
FeeTooLarge = c::FEE_TOO_LARGE,
EmissionFailure = c::EMISSION_FAILURE,
TooManyNonces = c::TOO_MANY_NONCES,
TooManyEmittedTxn = c::TOO_MANY_EMITTED_TXN,
NotImplemented = c::NOT_IMPLEMENTED,
InvalidAccount = c::INVALID_ACCOUNT,
GuardViolation = c::GUARD_VIOLATION,
InvalidField = c::INVALID_FIELD,
ParseError = c::PARSE_ERROR,
RcRollback = c::RC_ROLLBACK,
RcAccept = c::RC_ACCEPT,
NoSuchKeylet = c::NO_SUCH_KEYLET,
NotAnArray = -22,
NotAnObject = -23,
InvalidFloat = c::INVALID_FLOAT,
DivisionByZero = -25,
ManitssaOversized = -26,
MantissaUndersized = -27,
ExponentOversized = -28,
ExponentUndersized = -29,
Overflow = -30,
NotIouAmount = -31,
NotAnAmount = -32,
CantReturnNegative = -33,
}
impl Error {
#[inline(always)]
fn from_code(code: i32) -> Self {
unsafe { core::mem::transmute(code) }
}
#[inline(always)]
pub fn code(self) -> i32 {
self as _
}
}
type Api1ArgsU32 = unsafe extern "C" fn(u32) -> i64;
type Api2ArgsU32 = unsafe extern "C" fn(u32, u32) -> i64;
type Api3ArgsU32 = unsafe extern "C" fn(u32, u32, u32) -> i64;
type BufWriter = Api2ArgsU32;
type BufReader = Api2ArgsU32;
type BufWriter1Arg = Api3ArgsU32;
#[inline(always)]
fn api_1arg_call(arg: u32, fun: Api1ArgsU32) -> Result<u64> {
let res = unsafe { fun(arg) };
res.into()
}
#[inline(always)]
fn api_3arg_call(arg_1: u32, arg_2: u32, arg_3: u32, fun: Api3ArgsU32) -> Result<u64> {
let res = unsafe { fun(arg_1, arg_2, arg_3) };
res.into()
}
#[inline(always)]
fn buf_write(buf_write: &mut [u8], fun: BufWriter) -> Result<u64> {
let res = unsafe { fun(buf_write.as_mut_ptr() as u32, buf_write.len() as u32) };
res.into()
}
#[inline(always)]
fn buf_write_1arg(buf_write: &mut [u8], arg: u32, fun: BufWriter1Arg) -> Result<u64> {
let res = unsafe { fun(buf_write.as_mut_ptr() as u32, buf_write.len() as u32, arg) };
res.into()
}
#[inline(always)]
fn buf_read(buf: &[u8], fun: BufReader) -> Result<u64> {
let res = unsafe { fun(buf.as_ptr() as u32, buf.len() as u32) };
res.into()
}
#[inline(always)]
fn range_from_location(location: i64) -> core::ops::Range<usize> {
let offset: i32 = (location >> 32) as _;
let lenght: i32 = (location & 0xFFFFFFFF) as _;
core::ops::Range {
start: offset as _,
end: (offset + lenght) as _,
}
}
impl From<i64> for Result<u64> {
#[inline(always)]
fn from(res: i64) -> Self {
match res {
res if res >= 0 => Ok(res as _),
_ => Err(Error::from_code(res as _)),
}
}
}
impl From<Error> for i64 {
#[inline(always)]
fn from(err: Error) -> Self {
err as _
}
}
impl From<AccountType> for u8 {
#[inline(always)]
fn from(account_type: AccountType) -> Self {
account_type as _
}
}
impl From<AmountType> for u8 {
#[inline(always)]
fn from(amount_type: AmountType) -> Self {
amount_type as _
}
}
impl From<TxnType> for u8 {
#[inline(always)]
fn from(transaction_type: TxnType) -> Self {
transaction_type as _
}
}