use crate::_c;
mod control;
mod etxn;
mod float;
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 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 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 {
Generic = _c::sfGeneric,
LedgerEntry = _c::sfLedgerEntry,
Transaction = _c::sfTransaction,
Validation = _c::sfValidation,
Metadata = _c::sfMetadata,
Hash = _c::sfHash,
Index = _c::sfIndex,
CloseResolution = _c::sfCloseResolution,
Method = _c::sfMethod,
TransactionResult = _c::sfTransactionResult,
TickSize = _c::sfTickSize,
UNLModifyDisabling = _c::sfUNLModifyDisabling,
LedgerEntryType = _c::sfLedgerEntryType,
TransactionType = _c::sfTransactionType,
SignerWeight = _c::sfSignerWeight,
Version = _c::sfVersion,
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,
HookStateCount = _c::sfHookStateCount,
HookReserveCount = _c::sfHookReserveCount,
HookDataMaxSize = _c::sfHookDataMaxSize,
EmitGeneration = _c::sfEmitGeneration,
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,
EmitBurden = _c::sfEmitBurden,
HookOn = _c::sfHookOn,
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,
EmitParentTxnID = _c::sfEmitParentTxnID,
EmitNonce = _c::sfEmitNonce,
BookDirectory = _c::sfBookDirectory,
InvoiceID = _c::sfInvoiceID,
Nickname = _c::sfNickname,
Amendment = _c::sfAmendment,
TicketID = _c::sfTicketID,
Digest = _c::sfDigest,
PayChannel = _c::sfPayChannel,
ConsensusHash = _c::sfConsensusHash,
CheckID = _c::sfCheckID,
ValidatedHash = _c::sfValidatedHash,
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,
PublicKey = _c::sfPublicKey,
MessageKey = _c::sfMessageKey,
SigningPubKey = _c::sfSigningPubKey,
TxnSignature = _c::sfTxnSignature,
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,
NegativeUNLToDisable = _c::sfNegativeUNLToDisable,
NegativeUNLToReEnable = _c::sfNegativeUNLToReEnable,
HookData = _c::sfHookData,
Account = _c::sfAccount,
Owner = _c::sfOwner,
Destination = _c::sfDestination,
Issuer = _c::sfIssuer,
Authorize = _c::sfAuthorize,
Unauthorize = _c::sfUnauthorize,
Target = _c::sfTarget,
RegularKey = _c::sfRegularKey,
Paths = _c::sfPaths,
Indexes = _c::sfIndexes,
Hashes = _c::sfHashes,
Amendments = _c::sfAmendments,
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,
EmitDetails = _c::sfEmitDetails,
Signer = _c::sfSigner,
Majority = _c::sfMajority,
NegativeUNLEntry = _c::sfNegativeUNLEntry,
SigningAccounts = _c::sfSigningAccounts,
Signers = _c::sfSigners,
SignerEntries = _c::sfSignerEntries,
Template = _c::sfTemplate,
Necessary = _c::sfNecessary,
Sufficient = _c::sfSufficient,
AffectedNodes = _c::sfAffectedNodes,
Memos = _c::sfMemos,
Majorities = _c::sfMajorities,
NegativeUNL = _c::sfNegativeUNL,
}
#[derive(Clone, Copy)]
pub enum DataRepr {
AsUTF8 = 0,
AsHex = 1,
}
#[must_use]
pub enum Result<T> {
Ok(T),
Err(Error),
}
pub use self::Result::*;
#[must_use]
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(),
}
}
#[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 Api4ArgsU32 = unsafe extern "C" fn(u32, u32, u32, u32) -> i64;
type Api6ArgsU32 = unsafe extern "C" fn(u32, u32, u32, u32, u32, u32) -> i64;
type BufWriter = Api2ArgsU32;
type BufReader = Api2ArgsU32;
type Buf2Reader = Api4ArgsU32;
type BufWriterReader = Api4ArgsU32;
type Buf3Reader = Api6ArgsU32;
type BufWriter1Arg = Api3ArgsU32;
#[inline(always)]
fn api_1arg_call(arg: u32, fun: Api1ArgsU32) -> Result<u64> {
let res = unsafe { fun(arg) };
result_u64(res)
}
#[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) };
result_u64(res)
}
#[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) };
result_u64(res)
}
#[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) };
result_u64(res)
}
#[inline(always)]
fn buf_read(buf: &[u8], fun: BufReader) -> Result<u64> {
let res = unsafe { fun(buf.as_ptr() as u32, buf.len() as u32) };
result_u64(res)
}
#[inline(always)]
fn buf_2read(buf_1: &[u8], buf_2: &[u8], fun: Buf2Reader) -> Result<u64> {
let res = unsafe {
fun(
buf_1.as_ptr() as u32,
buf_1.len() as u32,
buf_2.as_ptr() as u32,
buf_2.len() as u32,
)
};
result_u64(res)
}
#[inline(always)]
fn buf_write_read(buf_write: &mut [u8], buf_read: &[u8], fun: BufWriterReader) -> Result<u64> {
let res = unsafe {
fun(
buf_write.as_mut_ptr() as u32,
buf_write.len() as u32,
buf_read.as_ptr() as u32,
buf_read.len() as u32,
)
};
result_u64(res)
}
#[inline(always)]
fn buf_3_read(
buf_read_1: &[u8],
buf_read_2: &[u8],
buf_read_3: &[u8],
fun: Buf3Reader,
) -> Result<u64> {
let res = unsafe {
fun(
buf_read_1.as_ptr() as u32,
buf_read_1.len() as u32,
buf_read_2.as_ptr() as u32,
buf_read_2.len() as u32,
buf_read_3.as_ptr() as u32,
buf_read_3.len() as u32,
)
};
result_u64(res)
}
#[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 _,
}
}
#[inline(always)]
fn all_zeroes(buf_write: &mut [u8], keylet_type_c: u32) -> Result<u64> {
let res = unsafe {
_c::util_keylet(
buf_write.as_mut_ptr() as _,
buf_write.len() as _,
keylet_type_c,
0,
0,
0,
0,
0,
0,
)
};
result_u64(res)
}
#[inline(always)]
fn buf_read_and_zeroes(buf_write: &mut [u8], buf_read: &[u8], keylet_type_c: u32) -> Result<u64> {
let res = unsafe {
_c::util_keylet(
buf_write.as_mut_ptr() as _,
buf_write.len() as _,
keylet_type_c,
buf_read.as_ptr() as _,
buf_read.len() as _,
0,
0,
0,
0,
)
};
result_u64(res)
}
#[inline(always)]
fn buf_read_and_1_arg(
buf_write: &mut [u8],
buf_read: &[u8],
arg: u32,
keylet_type_c: u32,
) -> Result<u64> {
let res = unsafe {
_c::util_keylet(
buf_write.as_mut_ptr() as _,
buf_write.len() as _,
keylet_type_c,
buf_read.as_ptr() as _,
buf_read.len() as _,
arg,
0,
0,
0,
)
};
result_u64(res)
}
#[inline(always)]
fn buf_read_and_2_args(
buf_write: &mut [u8],
buf_read: &[u8],
arg_1: u32,
arg_2: u32,
keylet_type_c: u32,
) -> Result<u64> {
let res = unsafe {
_c::util_keylet(
buf_write.as_mut_ptr() as _,
buf_write.len() as _,
keylet_type_c,
buf_read.as_ptr() as _,
buf_read.len() as _,
arg_1,
arg_2,
0,
0,
)
};
result_u64(res)
}
#[inline(always)]
fn buf_2_read_and_zeroes(
buf_write: &mut [u8],
buf_1_read: &[u8],
buf_2_read: &[u8],
keylet_type_c: u32,
) -> Result<u64> {
let res = unsafe {
_c::util_keylet(
buf_write.as_mut_ptr() as _,
buf_write.len() as _,
keylet_type_c,
buf_1_read.as_ptr() as _,
buf_1_read.len() as _,
buf_2_read.as_ptr() as _,
buf_2_read.len() as _,
0,
0,
)
};
result_u64(res)
}
#[inline(always)]
fn result_u64(res: i64) -> Result<u64> {
match res {
res if res >= 0 => Ok(res as _),
_ => Err(Error::from_code(res as _)),
}
}
#[inline(always)]
fn result_xfl(res: i64) -> Result<XFL> {
match res {
res if res >= 0 => Ok(XFL(res)),
_ => Err(Error::from_code(res as _)),
}
}