Xahau Network
Testnet FaucetExplorerHooks API Docs
Xahau Network
Xahau Network
  • πŸͺXahau Documentation
    • XRPL/Xahau: What is Different?
  • πŸͺHooks
  • 🚨Concepts
    • Introduction
      • Example Usage
      • Xahau Testnet
      • Xahau Testnet Explorer
      • Examples (source code)
      • Blogs (concepts)
    • Terminology
    • Loops and Guarding
    • Compiling Hooks
    • Chaining
    • Weak and Strong
    • Collect Call
    • SetHook Transaction
    • Parameters
    • Namespaces
    • Grants
    • HookOn Field
    • Reference Counted Hook Definitions
    • Hook Fees
    • Execution Metadata
    • Debugging Hooks
    • State Management
    • Slots and Keylets
    • Floating Point Numbers (XFL)
    • Emitted Transactions
    • Serialized Objects
  • Features
    • Public Nodes (RPC)
    • Amendments
    • Transaction Signing
      • Transaction Fees
    • Developer Tooling
      • Curated Tooling
      • Client Libraries
      • Developer Tricks
    • HTTP / WebSocket APIs
      • Request Formatting Guide
      • Response Formatting Guide
      • Considerations
      • Public API Methods
      • Admin API Methods
    • Network Features
      • Account Managment
      • Balance Rewards
      • Check
      • Escrow
      • Hooks
      • Offer
      • Payments
      • URIToken
    • Faucet & Explorers
    • Data API's
  • Infrastructure
    • Node Requirements
    • Running a Node
      • Running a Mainnet Node
      • Running a Testnet Node
    • Building Xahau (Dev)
      • Ubuntu - 22.04
      • Mac OS - 15.3.2 (24D81)
  • Technical
    • πŸ“Hooks Functions
      • Overview
        • Hook API Conventions
        • Return Codes
      • Developer Defined
        • hook
        • cbak / Callback
      • Control
        • accept
        • rollback
      • Utilities
        • util_raddr
        • util_accid
        • util_verify
        • util_sha512h
        • util_keylet
      • Serialization
        • sto_subfield
        • sto_to_json
        • sto_from_json
        • sto_subarray
        • sto_emplace
        • sto_erase
        • sto_validate
      • Emitted Transaction
        • etxn_burden
        • etxn_details
        • etxn_fee_base
        • etxn_nonce
        • etxn_reserve
        • etxn_generation
        • prepare
        • emit
      • Float
        • float_set
        • float_multiply
        • float_mulratio
        • float_negate
        • float_compare
        • float_sum
        • float_sto
        • float_sto_set
        • float_invert
        • float_divide
        • float_one
        • float_exponent
        • float_mantissa
        • float_sign
        • float_int
        • float_root
        • float_log
      • Ledger
        • fee_base
        • ledger_seq
        • ledger_last_hash
        • ledger_last_time
        • ledger_nonce
        • ledger_keylet
      • Hook Context
        • hook_account
        • hook_hash
        • hook_param
        • hook_param_set
        • hook_skip
        • hook_pos
        • hook_again
      • Slot
        • slot
        • slot_clear
        • slot_count
        • slot_set
        • slot_size
        • slot_subarray
        • slot_subfield
        • slot_type
        • xpop_slot
        • slot_float
      • State
        • state
        • state_set
        • state_foreign
        • state_foreign_set
      • Trace (Debug)
        • trace
        • trace_num
        • trace_float
      • Originating Transaction
        • otxn_burden
        • otxn_field
        • otxn_generation
        • otxn_id
        • otxn_type
        • otxn_slot
        • otxn_param
        • otxn_json
        • meta_slot
      • Websocket APIs
        • account_info
        • account_namespace
    • Protocol Reference
      • Transactions
        • Transaction Common Fields
        • Transaction Types
          • AccountDelete
          • AccountSet
          • CheckCancel
          • CheckCash
          • CheckCreate
          • ClaimReward
          • DepositPreauth
          • EscrowCancel
          • EscrowCreate
          • EscrowFinish
          • GenesisMint - (Emitted Txn)
          • Import
          • Invoke
          • OfferCancel
          • OfferCreate
          • Payment
          • PaymentChannelClaim
          • PaymentChannelCreate
          • PaymentChannelFund
          • Remit
          • SetHook
          • SetRegularKey
          • SignerListSet
          • TicketCreate
          • TrustSet
          • URITokenBurn
          • URITokenBuy
          • URITokenCancelSellOffer
          • URITokenCreateSellOffer
          • URITokenMint
        • Pseudo Transaction Types
          • EmitFailure
          • UNLReport
          • UNLModify
          • SetFee
          • EnableAmendment
        • Transaction Results
          • TES Codes
          • TER Codes
          • TEM Codes
          • TEL Codes
          • TEF Codes
          • TEC Codes
        • Transaction Metadata
      • Ledger Data
        • Ledger Objects Types
          • AccountRoot
          • Amendments
          • Check
          • Deposit Pre Auth
          • Directory Node
          • Emitted Txn
          • Escrow
          • Fee Settings
          • Hook
          • Hook Definition
          • Hook State
          • Import VL Sequence
          • Ledger Hashes
          • Negative UNL
          • Offer
          • Pay Channel
          • Ripple State
          • Signers List
          • Ticket
          • UNL Report
          • URIToken
        • Ledger Header
        • Ledger Object IDs
      • Data Types
        • Currency Formats
        • Base 58 Encodings
      • Binary Format
    • Balance Adjustments
    • Governance Game
    • Burn 2 Mint (B2M)
    • Versioning Process
  • Compliance
    • Security Audits
      • Responsible Disclosure
  • Support
    • Help Us
Powered by GitBook
On this page
  • Concepts
  • Behaviour
  • Definition
  • Example
  • Parameters
  • Return Code

Was this helpful?

Edit on GitHub
Export as PDF
  1. Technical
  2. Hooks Functions
  3. Float

float_sto

Output an XFL as a serialized object

Last updated 2 months ago

Was this helpful?

Concepts

Behaviour

  • Read an XFL floating point number and optionally a field code and currency code

  • Write a serialized amount to write_ptr according to the parameters provided

  • Stores a float representation into a specified field.

  • Returns an error code or the updated value as an array of numbers.

Definition

int64_t float_sto (
    uint32_t write_ptr,
    uint32_t write_len,
    uint32_t cread_ptr,
    uint32_t cread_len,  
    uint32_t iread_ptr,
    uint32_t iread_len,  
    int64_t float1,
    uint32_t field_code
);

function float_sto(
    currency: ByteArray | HexString | undefined,
    issuer: ByteArray | HexString | undefined,
    f1: bigint,
    field_code: number
  ): ErrorCode | ByteArray

Example

#define SBUF(str) (uint32_t)(str), sizeof(str)
uint8_t amt_out[48];
if (float_sto(SBUF(amt_out),
    SBUF(currency), SBUF(hook_accid), pusd_to_send, -1) < 0)
        rollback(SBUF("Peggy: Could not dump pusd amount into sto"), 1);

const amt_out = float_sto(currency, hook_accid, pusd_to_send, -1)
if (typeof amt_out === 'number')
        rollback("Peggy: Could not dump pusd amount into sto", 1)

Parameters

Name
Type
Description

write_ptr

uint32_t

Pointer to a buffer of a suitable size to store the serialized amount field. Recommend at least 48 bytes.

write_len

uint32_t

The length of the output buffer.

cread_ptr

uint32_t

Pointer to a buffer contianing the currency code to serialize into the output. May be null.

cread_len

uint32_t

The length of the currency code. This must be 20 or 3 or 0 (null).

iread_ptr

uint32_t

Pointer to a buffer containing the issuer's Account ID to serialize into the output. May be null.

iread_len

uint32_t

The length of the issuer's Account ID. This must be either 20 or 0 (null).

float1

int64_t

An XFL floating point enclosing number to serialize.

field_code

uint32_t

The sf field code to prefix the serialized amount with. E.g. sfAmount. If this field is 0xFFFFFFFFU (i.e. (uint32_t)(-1)) then no field code is prepended to the output, and no issuer or currency code is appended, but serialization proceeds as a floating point amount. If this field is 0 no field code is prepended to the output, and no issuer or currency code is appended, but serialization proceeds as though the amount is an XRP native amount rather than a floating point.

πŸ“˜Hint

To output an XAH amount prepopulate the field code in the output buffer then pass the output buffer incremented to the new start and 0 as field_code

Name
Type
Description

currency

ByteArray | HexString | undefined

The current value to store into.

issuer

ByteArray | HexString | undefined

The value to store.

f1

bigint

The field code indicating where to store the float.

field_code

number

An error code or the updated value as an array of numbers.

Return Code

Type
Description

int64_t

The number of bytes written to the output buffer. If negative, an error: INVALID_FLOAT - the supplied float was not a valid XFL enclosing number OUT_OF_BOUNDS - pointers/lengths specified outside of hook memory. INVALID_ARGUMENT - If instructed to output as XRP or without field code then all non-write pointers and lengths should be 0 (null). TOO_SMALL - The output buffer was too small to receive the serialized object. XFL_OVERFLOW - Expressing the output caused an overflow during normalization.

Type
Description

ErrorCode | ByteArray

Returns an error code or the updated value as an array of numbers.

πŸ“
Floating Point Numbers (XFL)
Serialized Objects