Module: XRBP::NodeStore::STAmount::Conversion
- Included in:
- XRBP::NodeStore::STAmount
- Defined in:
- lib/xrbp/nodestore/sle/st_amount_conversion.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #clear ⇒ Object
- #iou_amount ⇒ Object
- #negate! ⇒ Object
- #sn_value ⇒ Object
- #to_h ⇒ Object
-
#to_wire ⇒ Object
Encode STAmount into binary format.
-
#xrp_amount ⇒ Object
(also: #drops)
In drops!.
Instance Method Details
#clear ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 174 def clear # From rippled docs: # The -100 is used to allow 0 to sort less than a small positive values # which have a negative exponent. @exponent = native? ? 0 : -100 @neg = false @mantissa = 0 end |
#iou_amount ⇒ Object
197 198 199 |
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 197 def iou_amount (neg ? -1 : 1) * mantissa * 10 ** exponent end |
#negate! ⇒ Object
109 110 111 112 |
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 109 def negate! return if zero? @neg = !@neg end |
#sn_value ⇒ Object
184 185 186 |
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 184 def sn_value neg ? (-mantissa) : mantissa end |
#to_h ⇒ Object
102 103 104 105 106 107 |
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 102 def to_h {:mantissa => mantissa, :exponent => exponent, :neg => neg, :issue => issue.to_h} end |
#to_wire ⇒ Object
Encode STAmount into binary format
91 92 93 94 95 96 97 98 |
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 91 def to_wire xrp_bit = ((native? ? 0 : 1) << 63) neg_bit = (( neg ? 0 : 1) << 62) value_bits = native? ? mantissa : (((exponent+97) << 54) + mantissa) xrp_bit + neg_bit + value_bits end |
#xrp_amount ⇒ Object Also known as: drops
In drops!
191 192 193 |
# File 'lib/xrbp/nodestore/sle/st_amount_conversion.rb', line 191 def xrp_amount neg ? (-value) : value end |